Reputation: 35
I am developing an Android Application using an ActionBar which is changing in every Activity. I am using a NavDrawer and I want to CENTER and make the text WHITE. This text is the TITLE of the Activity chosen in the NavDrawer
Idioma.java
setHasOptionsMenu(true);
ActionBar actionbar=(getActivity()).getActionBar();
// SET ACTIONBAR LOGO
actionbar.setLogo(R.drawable.iconomenu);
actionbar.setHomeButtonEnabled(true);
// SET ACTIONBAR TITLE
actionbar.setDisplayShowTitleEnabled(true);
// SET ACTIONBAR BACKGROUNDIMAGE
BitmapDrawable background = new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.bgactionbar));
actionbar.setBackgroundDrawable(background);
View rootView = inflater.inflate(R.layout.fragment_idioma, container, false);
Upvotes: 0
Views: 1482
Reputation: 7449
you can use it in .java folder but in my experience ,use in styles.xml for seeing how it can be seeing which choose phone in android studio and it's example for you
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">android:color/red</item>
<item name="android:titleTextStyle">@style/MyActionBar.TitleTextStyle</item>
</style>
<style name="MyActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#FFFFFF</item>
</style>
Upvotes: 0
Reputation: 496
for changing the title color use html as below:
actionbar.setTitle(
Html.fromHtml("<font color='#FFFFFF'>"
+ YOUR_TITLE
+ "</font>"));
Upvotes: 0
Reputation: 3555
Create your own action bar layout file and use it like such:
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.my_custom_action_bar);
Upvotes: 1