我搜索过S.O.并尝试了许多解决方案,如:
How to change color of ActionBar's Title Text on Android 4.3 api 18
Change the title text color in android action bar via xml
但没有什么对我有用。我希望有人可以指出我缺乏理解。
这是我的Manifest片段:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/small_bc_logo"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".BckmMainActivity"
android:label="@string/app_name" >
我的styles.xml(res / values-14),我基本上是从我看到的第一个链接复制的:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/ActionBarStyle</item>
<!-- API 14 theme customizations can go here. -->
<item name="android:textColor">@color/black</item>
<item name="android:icon">@drawable/small_bc_logo</item>
</style>
<style name="ActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="android:titleTextStyle">@style/TitleBarTextColor</item>
</style>
<style name="TitleBarTextColor" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/red</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
我的colors.xml:
<resources>
<color name="red">#A52421</color>
<color name="black">#000000</color>
</resources>
我的strings.xml:
<resources>
<string name="app_name">BCKM</string>
<string name="action_settings">Settings</string>
</resources>
只是为了添加更多信息我的主要活动类:
public class BckmMainActivity extends ActionBarActivity {
private final Handler handler = new Handler();
private PagerSlidingTabStrip tabs;
private ViewPager pager;
private MyPagerAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bckm_main);
tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
pager = (ViewPager) findViewById(R.id.pager);
adapter = new MyPagerAdapter(getSupportFragmentManager());
pager.setAdapter(adapter);
final int pageMargin = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 4, getResources()
.getDisplayMetrics());
pager.setPageMargin(pageMargin);
tabs.setViewPager(pager);
}
...
...
...
非常感谢你。
答案 0 :(得分:3)
使用样式设置appcompat图标和标题文字颜色:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">@style/MyActionBar</item>
<item name="navigationIcon">@drawable/ic_launcher</item>
</style>
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="titleTextStyle">@style/TitleTextStyle</item>
<item name="displayOptions">showHome|showTitle</item>
</style>
<style name="TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#A52421</item>
</style>
以编程方式设置appcompat图标和标题文字颜色:
要在ActionBar标题上设置颜色,您需要使用SpannableString。默认情况下,图标未显示,因为appcompat-v7将setDisplayShowHomeEnabled
设置为false。致电super.onCreate(Bundle)
后,请添加以下代码:
SpannableString spannableString = new SpannableString(getString(R.string.app_name));
spannableString.setSpan(new ForegroundColorSpan(Color.RED), 0, spannableString.toString()
.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_launcher);
getSupportActionBar().setTitle(spannableString);
答案 1 :(得分:1)
这会改变文字颜色:
ActionBar ab = getActionBar();
ab.setTitle(Html.fromHtml("<font color='#ff0000'>YourTitleHere </font>"));