I am looking to change title color in my action bar for which I am trying out as below:
I have added the following in my Styles.xml (v14)
<style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">@style/MyTheme.ActionBarStyle</item>
<item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
<item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="drawerArrowStyle">@style/AppTheme.DrawerArrowToggle</item>
<item name="colorAccent">@color/greenText</item>
</style>
<style name="MyTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="background">@color/whiteText</item>
</style>
<style name="AppTheme.DrawerArrowToggle" parent="Base.Widget.AppCompat.DrawerArrowToggle">
<item name="color">@android:color/black</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/actionbar_blackText</item>
</style>
In my manifest: I using the same theme.
In my Activity Class: I changed the FragmentActivity to AppCompatActivity
the OnCreate looks like this:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayOptions(getSupportActionBar().getDisplayOptions() | android.support.v7.app.ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView imageView = new ImageView(getSupportActionBar().getThemedContext());
imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setImageResource(R.drawable.logoforactionbar);
android.support.v7.app.ActionBar.LayoutParams layoutParams = new android.support.v7.app.ActionBar.LayoutParams(android.support.v7.app.ActionBar.LayoutParams.WRAP_CONTENT, android.support.v7.app.ActionBar.LayoutParams.WRAP_CONTENT, Gravity.END | Gravity.CENTER_VERTICAL);
layoutParams.rightMargin = 20;
imageView.setLayoutParams(layoutParams);
getSupportActionBar().setCustomView(imageView);
getSupportActionBar().setTitle(getResources().getString(R.string.register_new));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setIcon(android.R.color.transparent);
setContentView(R.layout.register_new);
}
But the title text color doesn't change or I don't see the black up arrow too. The text and arrow are white...
It is strange that the same works fine on another AppCompatActivity which has the navigation drawer too.
I get the result like this:
I have cut the logo part. Anyways, There should be black title and black arrow but doesn't show up.
You just need to paste this and change your colors in this XML with your own
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimaryDark">#cc0986ff</item>
<item name="colorPrimary">#ff0c84e8</item>
<item name="android:textColorPrimary">#fdfff2</item>
<item name="android:windowBackground">@android:color/white</item>
<item name="android:editTextColor">@android:color/background_dark</item>
<item name="android:textColor">@android:color/background_dark</item>
<item name="colorControlNormal">@android:color/background_dark</item>
<item name="colorControlActivated">#ff0043c5</item>
<item name="colorControlHighlight">#ffcb6345</item>
</style>