Inside an activity I need to have fullscreen, but when the user taps to show the navigation bar the background color of the bar is always black.
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setSystemWindowFullScreen(this);
setContentView(R.layout.activity_layout);
ButterKnife.bind(this);
setFitsSystemWindows(this,rootView);
}
public void setSystemWindowFullScreen(Activity activity)
{
activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
int mUIFlag = View.SYSTEM_UI_FLAG_IMMERSIVE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
activity.getWindow().getDecorView().setSystemUiVisibility(mUIFlag);
}
public void setFitsSystemWindows(Activity activity,View rootView)
{
//Set Navigation bar style
activity.getWindow().setNavigationBarColor(Color.TRANSPARENT);
ViewCompat.setOnApplyWindowInsetsListener(rootView, (v, insets) -> {
((ViewGroup.MarginLayoutParams) v.getLayoutParams()).topMargin =
insets.getSystemWindowInsetTop();
return insets.consumeSystemWindowInsets();
});
}
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:fitsSystemWindows">true</item>
<item name="android:windowDisablePreview">true</item>
</style>
What am I missing?
You can do this in styles.xml :
<item name="android:navigationBarColor">@color/theme_color</item>
or
window.setNavigationBarColor(@ColorInt int color)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.