【问题标题】:Dark-text transparent status bar with opaque navigation bar带有不透明导航栏的暗文本透明状态栏
【发布时间】:2018-03-15 10:03:11
【问题描述】:

等等,它不是重复的

here 已提出类似问题,但未解决暗文本状态栏。

我想做什么

我想同时实现三件事:

  1. 透明状态栏(不隐藏!)
  2. 深色文本状态栏
  3. 不透明(或黑色)导航栏(不会让活动内容在其下方膨胀)

我尝试过的

解决办法

            getWindow().getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

只能实现1和3;

解决方案here只能实现1和2;

而解决方案here只能实现2和3....

问题

那么有没有办法实现所有1、2和3?!

【问题讨论】:

  • The solution here can only achieve 1 and 2 但是在那个答案中,导航栏是透明的,并且活动的内容被绘制在它的下方。而你已经告诉过你想要Opaque (or black) navigation bar (which does not let activity content inflate underneath it)。你的要求不是很清楚。
  • 我的要求很明确,你已经得到了,我想要不透明的导航栏但是那个答案只能实现透明的导航栏。矛盾在哪里?
  • 现在我明白了,是我的错
  • @azizbekian 别介意,你的回答很有魅力!

标签: android android-view statusbar android-windowmanager android-window


【解决方案1】:

内部styles.xml:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    ...
    <item name="android:navigationBarColor">@android:color/black</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

在活动的onCreate():

override fun onCreate(savedInstanceState: Bundle?) {
  window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
  super.onCreate(savedInstanceState)
  setContentView(R.layout.activity_main)
}

将导致:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-27
    • 2021-09-27
    • 1970-01-01
    • 1970-01-01
    • 2018-10-13
    • 2017-08-28
    • 1970-01-01
    • 2021-02-26
    相关资源
    最近更新 更多