[英]How to change the color of text in the android action bar in Android Lollipop?
No matter what I do, the action bar text is black, I need to change it to white. 无论我做什么,操作栏文本都是黑色的,我需要将其更改为白色。
I have tried this 我已经试过了
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:colorPrimary">@color/primary_color</item>
<item name="android:actionBarStyle">@style/AppTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="AppTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Medium">
<item name="android:textColorPrimary">@android:color/white</item>
</style>
and this 和这个
int titleId = getResources().getIdentifier("action_bar_title", "id", "android");
TextView abTitle = (TextView) findViewById(titleId);
abTitle.setTextColor(colorId);
the second answer from here How to change action bar title color in code , just crashes the program, the first answer doesn't work. 这里的第二个答案如何在代码中更改操作栏标题的颜色 ,只会使程序崩溃,第一个答案无效。 Please help?? 请帮忙??
Copy the style.xml
inside a new directory called values-v21
and then simply replace with this: 将style.xml
复制到一个名为values-v21
的新目录中,然后简单地替换为:
<resources>
<!-- inherit from the material theme -->
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">@color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">@color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">@color/accent</item>
</style>
For more information see Maintaining Compatibility 有关更多信息,请参见维护兼容性。
This must work: Add it to res/values/styles.xml 这必须工作:将其添加到res / values / styles.xml
<resources>
<style name="AppTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:colorPrimary">@color/primary_color</item>
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:titleTextStyle">@style/Textstyle</item>
</style>
<style name="Textstyle" parent="@android:style/Widget.TextView">
<item name="android:textColor">@android:color/white</item>
</style>
</resources>
And change your AndroidManifest: 并更改您的AndroidManifest:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"> // <--------- Here -------->
<activity
android:name=".Main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.