[英]android : setting status and navigation bar color
For my activity, i am setting a background color for the window as 对于我的活动,我将窗口的背景色设置为
window.decorView.setBackgroundResource(R.drawable.background_red)
Now i want the status and navigation to get a darker shade over this background. 现在,我希望状态和导航在此背景上变得更暗。 How can i get this.
我怎么能得到这个。 I tried setting the theme as
我尝试将主题设置为
`<style name="Theme.OnArrival.AccessControl" parent="Theme.OnArrival.Light">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>`
but it doesnt seem to be working for navigation bar. 但它似乎不适用于导航栏。 Whats the right way to do it
什么是正确的方法
To programmatically set status bar color use below code: 要以编程方式设置状态栏颜色,请使用以下代码:
Window window = activity.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(ContextCompat.getColor(activity,R.color.statusbar_color));
Or set colorPrimaryDark
in your Theme. 或在主题中设置
colorPrimaryDark
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.