【问题标题】:Hide StatusBar when displaying BottomSheetDialog显示 BottomSheetDialog 时隐藏状态栏
【发布时间】:2019-11-19 08:25:42
【问题描述】:

我有一个全屏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);

然后我显示一个BottomSheetDialog,如下图:

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

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

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

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

【问题讨论】:

  • 嗨..我刚试过,对我来说效果很好。让我发布我尝试过的内容..
  • @sanjeev 好的,谢谢,我正在等待您的回复。

标签: java android android-bottomsheetdialog


【解决方案1】:

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

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

这适用于显示带有BottomSheetDialogFragment 的模态底部工作表对话框时。在运行 Android 8.0 的设备上进行了测试。

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

【讨论】:

    【解决方案2】:

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

    这是我的v21/styles.xml:

    P.S:我已经在我的主题中将它用于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>
    

    我已将其应用于&lt;activity&gt; 之类的,

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

    【讨论】:

    • 我会试试这个并回复你。谢谢你的回答。
    • 这个我试过了,但是状态栏还是显示出来的。
    • 我没有使用这个&lt;item name="android:windowContentOverlay"&gt;@null&lt;/item&gt; 或在onCreate 中声明任何内容..
    • 我删除了它,但仍然没有运气
    • @HB 尝试不同的设备
    【解决方案3】:

    我通过在对话框 show() 方法之后调用 hideStatusBar 来解决这个问题。我使用 kotlin 风格。

        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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-14
      • 2012-01-06
      • 2017-12-03
      相关资源
      最近更新 更多