具有BottomNavigationView的渐变状态栏 [英] Gradient status bar with BottomNavigationView

查看:437
本文介绍了具有BottomNavigationView的渐变状态栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我尝试了以下解决方案:


  1. 如何在Android中将状态栏背景设置为渐变颜色或可绘制对象

  2. 状态栏&上的Google即时渐变/阴影导航栏

  3. 如何在Android中将渐变应用于状态栏?

  4. 如何删除底部屏幕上的按钮栏

我的代码如下:



->在Java代码中,我尝试过:

 如果(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模式:

 查看decorView = getWindow()。getDecorView(); 
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE
//将内容设置为显示在系统栏下方,以便
//在隐藏和隐藏系统栏时不会调整大小show。
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
//隐藏导航栏和状态栏
| View.SYSTEMIDE_UI_FLAG b | 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>

任何一种帮助都是可取的。谢谢!

解决方案

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



您需要更改根布局



CoordinatorLayout 设置为您的根布局



使用



android.support.design.widget .CoordinatorLayout



而不是



RelativeLayout



使用 RelativeLayout





使用 android.support.design.widget.CoordinatorLayout


In my Application I want to show gradient status bar. Also i have used BottomNavigationView. So issue is when i am doing status bar gradient the bottom navigation bar of android overlaps the BottomNavigationView.

I have tried below solutions :

  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

My code is as below :

-- > In java code i tried :

 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);
        }

Issue :: With this java code i have achieved status bar issue but bottom navigation bar of android overlaps the BottomNavigationView.

-- > Also I have tried in style with :

<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>

Issue :: But getting some dark color status bar by this code.

-- > Also I have tried immersive mode of 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);

Issue :: But it hides the status bar and bottom navigation which i don't want to.

******************* EDIT *******************

Tried in activity :

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);
        }

In layout :

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

In style :

 <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>

Any kind of help would be appreciable. Thank you !

解决方案

You above code is working fine for me

You need to change your root layout

Make CoordinatorLayout as your root layout

Use

android.support.design.widget.CoordinatorLayout

Instead of

RelativeLayout

SEE the output using RelativeLayout

Output using android.support.design.widget.CoordinatorLayout

这篇关于具有BottomNavigationView的渐变状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆