简体   繁体   English

动作栏标题文字颜色

[英]Action Bar Title Text Color

I am having an Activity that extends the AppCompatActivity. 我有一个扩展AppCompatActivity的Activity。 I am using the theme Theme.AppCompat.Light.DarkActionBar . 我正在使用主题Theme.AppCompat.Light.DarkActionBar Now, the text color of the TitleText in the ActionBar shows up black. 现在,ActionBar中TitleText的文本颜色显示为黑色。 I want to set this color to white. 我想将此颜色设置为白色。

How can this be possibly achieved ? 如何做到这一点? Do I change the theme to something else (if yes then what) or can I change the color by making changes through the ThemeEditor available in the latest version of the Android Studio or can something be done with the getSupportActionBar() programmatically ? 我是否可以将主题更改为其他内容(如果是,则更改内容),还是可以通过最新版本的Android Studio中可用的ThemeEditor进行更改来更改颜色,或者可以通过编程方式使用getSupportActionBar()完成某些操作?

I personally chose the programmatical way. 我个人选择了编程方式。

In your code, you can assign a custom layout to your ActionBar . 在代码中,您可以将自定义布局分配给ActionBar

Like this: 像这样:

android.support.v7.app.ActionBar mActionBar = getSupportActionBar();
mActionBar.setDisplayShowTitleEnabled(false);
mActionBar.setDisplayUseLogoEnabled(false);
mActionBar.setDisplayHomeAsUpEnabled(false);
mActionBar.setDisplayShowCustomEnabled(true);
mActionBar.setDisplayShowHomeEnabled(false);


ViewGroup actionBarLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.topbarclassic,null);
mActionBar.setCustomView(actionBarLayout);

Then just change the text color of your textview containing the text inside the ActionBar as following: 然后只需更改包含ActionBar内文本的textview的文本颜色,如下所示:

        android:textColor="#FFFFFF"

You can simply change the action bar tittle color using this code You add below code to your Oncreate method 您可以使用此代码简单地更改操作栏标题的颜色。将以下代码添加到Oncreate方法中

setTitleColor(YOUR COLOR);

Hope this helps. 希望这可以帮助。

尝试在您的Activity这样做

getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#DCDCDC"))); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM