显示BottomSheet对话框时隐藏StatusBar



我有一个全屏Activity,下面是关于如何使其全屏的所有相关代码:


Manifest.xml

<activity
android:name=".Player"
android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen.player" />

styles.xml

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen.player" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>

活动onCreate

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

I然后显示BottomSheetDialog,如下所示:

bottomSheetDialog = new BottomSheetDialog(this);
bottomSheetDialog.setContentView(dialogView);
bottomSheetDialog.show();

我遇到的问题是,当我显示BottomSheetDialog时,也会显示StatusBar

我注意到,当显示应用内购买对话框时,StatusBar是隐藏的,在我看来它就像是BottomSheetDialog

当我显示BottomSheetDialog时,如何不显示StatusBar

我已经将主题应用于我的BottomSheetDialog,它非常适合我。

这是我的v21/styles.xml:

附言:我已经在主题中使用了windowContentTransitions,因此没有必要使用。

<style name="AppTheme.RoundedBottomDialog">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:popupMenuStyle">@style/PopupMenu</item>
<item name="bottomSheetDialogTheme">@style/AppBottomSheetDialogTheme</item>
</style>
<style name="AppBottomSheetDialogTheme"
parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">@style/AppModalStyle</item>
</style>
<style name="AppModalStyle"
parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">@drawable/white_bottom_sheet</item>
</style>

这是我的styles.xml:

<style name="AppTheme.RoundedBottomDialog">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:popupMenuStyle">@style/PopupMenu</item>
<item name="bottomSheetDialogTheme">@style/AppBottomSheetDialogTheme</item>
</style>
<style name="AppBottomSheetDialogTheme"
parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">@style/AppModalStyle</item>
</style>
<style name="AppModalStyle"
parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">@drawable/white_bottom_sheet</item>
</style>

我已经将它应用于<activity>,如

<activity
android:name=".SomeActivity"
android:configChanges="locale|orientation|keyboardHidden"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.RoundedBottomDialog"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden" />

回答这个问题可能会迟到。供其他人参考,当在返回onCreateView方法之前设置了以下标志时,StatusBar将不会显示:

dialog?.window?.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN)

这适用于使用BottomSheetDialogFragment显示模式底部图纸对话框时。在运行Android 8.0的设备上进行了测试。

对于具有BottomSheetBehavior的持久性底部表单,只需将全屏主题应用于Activity或将Activity的主题上的android:windowFullscreen属性设置为true即可。

我通过在dialog show((方法之后调用hideStatusBar来解决这个问题。我使用科特林风格。

fun hideStatusBar() {
val uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
View.SYSTEM_UI_FLAG_FULLSCREEN
window?.decorView?.systemUiVisibility = uiOptions
}

最新更新