英文:
How to change the color of the navigation and status bar on Android Java?
问题
这是我第一次在 Android 中进行编程,我想要更改状态栏和导航栏的颜色,我阅读了文档,似乎很简单,但是对我来说不起作用。
我将展示我添加的内容,但如果您需要更多信息,我会发布出来。
Window window = getWindow();
window.setStatusBarColor(R.color.colorWhite);
window.setNavigationBarColor(R.color.colorWhite);
所有它做的只是将栏进行了明确的设置。
英文:
It is my first time programming in android and I want to change the color of the bars, I read the documentation it seems simple but it does not work for me.
I am going to show what I add but if you need more information I will post it.
Window window = getWindow();
window.setStatusBarColor(R.color.colorWhite);
window.setNavigationBarColor(R.color.colorWhite);
All it does is clarify the bar
答案1
得分: 0
从Java类:
通过调用资源获取颜色,可以这样做:
Window window = getWindow();
window.setStatusBarColor(getResources().getColor(R.color.colorWhite));
window.setNavigationBarColor(getResources().getColor(R.color.colorSome));
这个颜色可以从styles.xml文件中的AppTheme
进行更改。它的值可以从属性<item name="colorPrimaryDark">#yourColor</item>
进行更改。
styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- 在这里自定义您的主题。 -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
它们的颜色在colors.xml中可用:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
阅读文档。
英文:
From java class:
Get color by calling resources, do this way:
Window window = getWindow();
window.setStatusBarColor(getResources().getColor(R.color.colorWhite));
window.setNavigationBarColor(getResources().getColor(R.color.colorSome));
This color can be changed from your AppTheme
in styles.xml file. It's value can be changed from attribute <item name="colorPrimaryDark">#yourColor</item>
styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
Their colors are available in colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
Read the documentation.
答案2
得分: 0
我认为你可能想看看这个:
https://stackoverflow.com/questions/39341818/how-to-change-the-color-of-the-status-bar-in-android/39341866#:~:text=你可以通过在xml中添加
看起来你做得很好,但是似乎有些东西丢失了。
英文:
I think you might like to have a look at this
It appears that you're doing fine but something is missing
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论