【问题标题】:status and navigation bar design [duplicate]状态和导航栏设计
【发布时间】:2018-01-08 14:06:49
【问题描述】:

如何让状态栏透明,隐藏导航栏?

例如,

【问题讨论】:

    标签: android


    【解决方案1】:

    您需要做的就是在您的主题中设置这些属性:

    <item name="android:windowTranslucentStatus">true</item>
    

    您希望拥有透明状态栏的活动/容器布局需要此属性集:

    android:fitsSystemWindows="true"
    

    要隐藏导航栏,请在您的活动中使用此代码onCreate()

    View decorView = getWindow().getDecorView();
    // Hide both the navigation bar and the status bar.
    // SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
    // a general rule, you should design your app to hide the status bar whenever you
    // hide the navigation bar.
    int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                  | View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(uiOptions);
    

    【讨论】:

    • 感谢您的回复。我从你的回答中得到了我需要的东西!
    • 不客气。快乐编码:)
    【解决方案2】:

    在创建新活动时选择空活动。

    如果您只想要一个没有操作栏的主题,您可以使用“NoActionBar”变体,例如。如果您的基本主题如下

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    

    那么你可以使用

    <style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    

    但如果您想保留主主题的属性,即 AppTheme,您可以执行以下操作

    <style name="AppThemeNoActionBar" parent="AppTheme">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
    

    您可以通过这种方式保留基本主题的所有属性,而不必在 NoActionBar 主题中显式添加它们:)

    【讨论】:

      【解决方案3】:

      你的风格

         <style name="AppTheme.TransparentActivity">
          <item name="android:windowFullscreen">true</item>
          <item name="android:windowBackground">@android:color/transparent</item>
          <item name="android:windowIsTranslucent">true</item>
          <item name="windowNoTitle">true</item>
         </style>
      

      在你的清单文件中

          <activity
              android:name=".MainActivity"
              android:theme="@style/AppTheme.TransparentActivity">
           </activity>
      

      【讨论】:

        猜你喜欢
        • 2017-04-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多