如何在android活动中更改标题栏颜色?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2386867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:39:10  来源:igfitidea点击:

How to change title bar color in android activity?

androidlayoutandroid-activity

提问by UMAR

Possible Duplicate:
Set title background color

可能的重复:
设置标题背景颜色

How can I change the titlebar color in an Android app?

如何更改 Android 应用程序中的标题栏颜色?

I tried:

我试过:

this.setTitleColor(Color.BLUE); 

but it changes color of written text on it not title bar color.

但它会改变其上书面文字的颜色,而不是标题栏的颜色。

回答by Dwivedi Ji

getWindow() method of Context return the current view context, for get the title bar of an Activity, android.id.id.title

Context 的 getWindow() 方法返回当前视图上下文,用于获取 Activity 的标题栏,android.id.id.title

View title = getWindow().findViewById(android.R.id.title);
View titleBar = (View) title.getParent();
titleBar.setBackgroundColor(Color.RED);`