[英]DialogFragment does not occupy bezel less screen
我試圖在一個有缺口的bezeless手機中顯示一個對話框片段。 這是截圖。
如您所見,對話框片段不會占據整個屏幕,並在頂部顯示丑陋的灰色。
這是我嘗試過的
我在DialogFragment中設置樣式
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(DialogFragment.STYLE_NORMAL, R.style.FullScreenDialogStyle)
}
<style name="FullScreenDialogStyle" parent="Theme.AppCompat.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
我使用相同的技術進行活動屏幕,它可以工作,因為它占據整個無邊框屏幕,但這不適用於對話框片段
你有兩個選擇。 首先,讓我們看看兩個選項共有的組件;
DialogFragment的onStart方法:
override fun onStart() {
super.onStart()
val dialog: Dialog? = dialog
if (dialog != null) {
val width = ViewGroup.LayoutParams.MATCH_PARENT
val height = ViewGroup.LayoutParams.MATCH_PARENT
dialog.window?.setLayout(width, height)
dialog.window?.decorView?.systemUiVisibility =
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_FULLSCREEN
}
}
DialogFragment的onCreate方法:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(DialogFragment.STYLE_NORMAL, R.style.FullScreenDialogStyle)
}
Dialog xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#c92145">
<Button android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Lorem ipsum dolor sit amet"/>
</LinearLayout>
FullScreenDialogStyle:
<style name="FullScreenDialogStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
左(選項#1)
將此行添加到FullScreenDialogStyle
<item name="android:fitsSystemWindows">true</item>
對(選項#2)
將此行添加到FullScreenDialogStyle
<item name="android:fitsSystemWindows">false</item>
在您的代碼中,您應該包含android“ windowMinWidthMajor ”和“ windowMinWidthMinor ”屬性,並將dialog.getWindow()布局設置為MATCH_PARENT並在LinearLayout中進行布局。
<style name="Theme_Dialog_tab" parent="Theme.AppCompat.Dialog">
<item name="android:windowMinWidthMajor">100%</item>
<item name="android:windowMinWidthMinor">100%</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowBackground">@null</item>
</style>
在Java文件中:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(),R.style.Theme_Dialog);
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
我希望它會幫助你......!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.