【问题标题】:Gradient status bar with BottomNavigationView带有 BottomNavigationView 的渐变状态栏
【发布时间】:2018-10-04 05:59:51
【问题描述】:

在我的应用程序中,我想显示渐变状态栏。我也用过BottomNavigationView。所以问题是当我在做状态栏渐变时,android的底部导航栏与BottomNavigationView重叠。

我尝试了以下解决方案:

  1. how to set status bar background as gradient color or a drawable in android
  2. Google Now gradient/shadow on status bar & navigation bar
  3. How to apply gradient to status bar in android?
  4. How to remove button bar at the bottom screen

我的代码如下:

--> 在 java 代码中我尝试过:

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window w = getWindow();
            w.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
            w.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }

问题 :: 使用此 java 代码,我已经实现了状态栏问题,但 android 的底部导航栏与 BottomNavigationView 重叠。

--> 我也尝试过风格:

<item name="android:windowFullscreen">false</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:windowIsTranslucent">true</item>

问题 :: 但是通过这段代码得到一些深色状态栏。

--> 我也试过android的沉浸式模式:

View decorView = getWindow().getDecorView();
        decorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_IMMERSIVE
                        // Set the content to appear under the system bars so that the
                        // content doesn't resize when the system bars hide and show.
                        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        // Hide the nav bar and status bar
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_FULLSCREEN);

问题 :: 但它隐藏了我不想隐藏的状态栏和底部导航。

************************ 编辑 *******************

在活动中尝试过:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        } else {

            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }

在布局中:

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

风格:

 <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
        <item name="android:windowActionBar">false</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowNoTitle">true</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:windowTranslucentNavigation">false</item>
        <item name="android:navigationBarColor">#000</item>
        <item name="colorControlNormal">#FFFFFF</item>
 </style>

任何形式的帮助都将是可观的。谢谢!

【问题讨论】:

  • @NileshRathod 我得到的是白色状态栏,而不是你给定的答案。我有不同的工具栏布局我在那里给了 fitSystemWindow true 并且还在底部导航视图活动中添加了这个。还设置透明初级暗。仍然没有运气。你能检查一下吗
  • 您能否用相关代码和预期输出编辑您的问题,以便我可以帮助您
  • @NileshRathod 请检查已编辑的问题。我的设备是 6.0.1
  • 预期输出的图像在哪里
  • 测试用例使android.support.design.widget.CoordinatorLayout你的rootlayout

标签: android android-layout gradient android-statusbar android-bottom-nav-view


【解决方案1】:

上面的代码对我来说很好用

你需要改变你的根布局

CoordinatorLayout 设为您的根布局

使用

android.support.design.widget.CoordinatorLayout

代替

RelativeLayout

使用 RelativeLayout

查看输出

使用 android.support.design.widget.CoordinatorLayout

输出

【讨论】:

  • 在包含活动休息的底部导航中仍然存在同样的问题。我只需要在所有片段或父活动中添加此代码吗? fitsystem 窗口代码
  • @Annie 可能是因为我没有在片段中测试过这段代码
  • @Annie 为什么不问新问题
  • issue kya ave che m k mne nvo question puchi to koik duplicate mari deshe
  • 发行kya ave che
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-24
  • 2017-04-19
  • 1970-01-01
  • 2018-09-11
  • 2014-01-19
  • 1970-01-01
相关资源
最近更新 更多