Last active
June 26, 2019 03:26
-
-
Save linsea/dc6ff5571c33e3e2768c8839c0c78055 to your computer and use it in GitHub Desktop.
full width dialog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. https://stackoverflow.com/questions/28513616/android-get-full-width-for-custom-dialog | |
2. 还有一个技巧是在 DialogFragmnet 的 onStart() 方法里设置 window 的属性, 如下的答案有提到: | |
https://stackoverflow.com/questions/2306503/how-to-make-an-alert-dialog-fill-90-of-screen-size | |
3. 需求是屏幕最底下弹出一个包含 EditText 的 Dialog, 并且宽度占满屏幕的宽度, 点击输入框后, 输入法把 Dialog 顶上来. 实现如下. | |
i) Dialog 的内容布局使用 android:layout_gravity="bottom" 属性, 因为系统给 dialog 的父布局是一个 FrameLayout, 这样内容子布局就对齐到了屏幕的底部. | |
ii) 创建 Dialog: | |
val buttomFullWidthDialog = Dialog(this, R.style.DialogFullWidth) | |
// 设置输入法属性, 否则键盘会盖住dialog的下半部分, 无法完全把 dialog 顶上去. | |
buttomFullWidthDialog.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | |
or WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE) | |
buttomFullWidthDialog.setContentView(R.layout.dialog_report_user) | |
buttomFullWidthDialog.show() | |
其中 R.style.DialogFullWidth 为: | |
<style name="DialogFullWidth" parent="Theme.AppCompat.Dialog"> | |
<item name="android:windowNoTitle">true</item> | |
<item name="android:windowBackground">@color/transparent</item> | |
<item name="android:windowIsFloating">false</item> <!-- 不设置它的话Dialog边缘与屏幕边缘会有margin, 即dialog不会贴边显示 --> | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment