【发布时间】:2018-10-04 05:59:51
【问题描述】:
在我的应用程序中,我想显示渐变状态栏。我也用过BottomNavigationView。所以问题是当我在做状态栏渐变时,android的底部导航栏与BottomNavigationView重叠。
我尝试了以下解决方案:
- how to set status bar background as gradient color or a drawable in android
- Google Now gradient/shadow on status bar & navigation bar
- How to apply gradient to status bar in android?
- 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