ActionBar custom header as ImaveView instead of TextView

I am trying to get around this in the action bar, but from what I see in the title, it is basically a TextView, but I need to place the image instead of plain text. I am trying to install it in style themes.xml as follows:

<item name="android:actionBarStyle">@style/MyActionBar</item> 

And then I defined this style

  <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar"> <item name="android:background">@drawable/action_background</item> <item name="android:titleTextStyle">@style/ActionbarTitleStyle</item> </style> 

I thought I could define a background for the name, but even if I do it not what I want, try getActionBar (). setCustomView (layout); but I realized that my actionbar is null before calling setContentView, and I need it in the base class.

PD. I only need to take care of HONEYCOMB and Higher, so if you do not offer an implementation of Sherlock or Jonanilson.

+8
android android-actionbar customization
source share
2 answers

if you want an image, you can specify the application logo with the icon (it will be used instead of the icon):

 <application android:icon="@drawable/ic_launcher" android:logo="@drawable/logo" android:label="@string/app_name" android:name=".AppName" > 

You now have a custom image instead of the lanucher icon. What you need to do next is get rid of the text. In your styles, do something like:

 <style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.ActionBar"> <item name="titleTextStyle">@style/NoTitleText</item> <item name="android:titleTextStyle">@style/NoTitleText</item> <item name="subtitleTextStyle">@style/NoTitleText</item> <item name="android:subtitleTextStyle">@style/NoTitleText</item> </style> <style name="NoTitleText"> <item name="android:textSize">0sp</item> <item name="android:textColor">#00000000</item> </style> 

You should use both item name="titleTextStyle" and item name="android:titleTextStyle" if you use ActionBarSherlock if I remember well.

+16
source share

Replace setContentView as follows:

 @Override public void setContentView(int resLayoutId) { super.setContentView(resLayoutId); // TODO Set your actionbar changes here } 

OR, you can do this:

 <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar"> <item name="android:background">@drawable/action_background</item> <item name="android:titleTextStyle">@style/ActionbarTitleStyle</item> <item name="android:displayOptions">showCustom</item> <item name="android:customNavigationLayout">@layout/custom_nav_layout</item> </style> 
+1
source share

All Articles