通过全屏活动在Android Lollipop上设置navigationBar颜色 [英] Set navigationBar color on Android Lollipop with Full screen activity
问题描述
是否可以在全屏活动中设置导航栏颜色?
Is there a way to set the navigationbar color in a fullscreen activity?
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setNavigationBarColor(getResources().getColor(R.color.Theme_color));
这行是我的主题风格:
<item name="android:navigationBarColor" tools:targetApi="21">#E64A19</item>
两者都会在我的活动布局上方产生相同的透明导航栏...
Both resulting in the same transparant navbar above my activities layout...
代码:
积极性:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow()
.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_account);
if (getResources().getBoolean(R.bool.portrait_only)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow()
.setNavigationBarColor(getResources().getColor(R.color.Theme_color));
}
//other code ... (irrelevant)
主题:
<style name="FullscreenTheme" parent="android:Theme.NoTitleBar">
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@null</item>
<item name="metaButtonBarStyle">@style/ButtonBar</item>
<item name="metaButtonBarButtonStyle">@style/ButtonBarButton</item>
<item name="android:navigationBarColor" tools:targetApi="21">#E64A19</item>
</style>
结果是黑色导航栏.但是我想要一个橙色的(#E64A19)导航栏.
The result is a black navigationbar. But I want a orange (#E64A19) navigation-bar.
结果:
推荐答案
我的解决方案:
一旦我从主题样式(以及除<item name="android:navigationBarColor" tools:targetApi="21">#E64A19</item>
以外的所有其他内容)中删除了parent="android:Theme.NoTitleBar"
属性,问题就在于生成的代码(XML主题),我的导航栏变成了橙色!
The problem lied with the generated code (XML theme) once I'd deleted the parent="android:Theme.NoTitleBar"
attribute from my theme style (and everything else except <item name="android:navigationBarColor" tools:targetApi="21">#E64A19</item>
) my navbar became orange!
结果:
这篇关于通过全屏活动在Android Lollipop上设置navigationBar颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!