【问题标题】:How to hide status bar and navigation bar using Theme.MaterialComponents如何使用 Theme.MaterialComponents 隐藏状态栏和导航栏
【发布时间】:2019-10-02 09:23:11
【问题描述】:

我在应用中隐藏状态和导航栏时遇到了一些问题。

假设:

  • 使用库 com.google.android.material:material:1.1.0-alpha10
  • 使用样式 Theme.MaterialComponents.Light.NoActionBar

类似的解决方案

window.apply {
      clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
       addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
        } else {
            decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        }
        statusBarColor = Color.TRANSPARENT
}

不能正常工作

【问题讨论】:

    标签: android android-statusbar material-components-android


    【解决方案1】:
    1. 在styles.xml 中创建新主题:
     <style name="AppTheme.NoActionBar" parent="Theme.MaterialComponents.Light.NoActionBar">
        <item name="android:windowBackground">@color/white</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="windowNoTitle">true</item>
    </style>
    
    1. 在 Manifest 中应用此主题(用于所需活动)
    <activity
        android:name=".SearchActivity"
        android:label="Text"
        android:theme="@style/AppTheme.NoActionBar" />
    

    【讨论】:

    • 状态栏和导航栏不是操作栏
    • 我的假设是使用样式 Theme.MaterialComponents.Light.NoActionBar
    • @Skalaw,添加了父母。
    • &lt;item name="android:windowFullscreen"&gt;true&lt;/item&gt; 是我需要的。谢谢@Webfreak!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多