Custom image instead of logo in ActionBar / ActionBarSherlock

How can I change the default ActionBar logo icon as a custom image? Like on whatsapp? Whatsapp custom image as logo

+7
android actionbarsherlock image android-actionbar graphical-logo
source share
4 answers

The ActionBar uses the android attribute : the logo of your manifest, if one is provided. This allows you to use the individual available resources for the icon (Launcher) and logo (ActionBar, by the way).


So you should add this tag to the manifest as ..

<application android:logo="@drawable/custom_image" 

Update:

You can use ActionBar.setLogo() for runtime. There are two versions of setLogo (int resId) and setLogo (Drawable logo) .

Consider Define a custom logo for an ActionBar (other than a logo) in XML? , which will also help you identify some styles.

+3
source share

The easiest way is to use setIcon (R.drawable.icon_name). Similarly, you can do this with Title, and you can also set the date in the subtitles of the action bar.

 ActionBar ab= getActionBar(); ab.setTitle("Aries"); ab.setSubtitle(dateFormat.format(date)); ab.setIcon(R.drawable.aries3d); 
+1
source share

You need to configure ActionBarSherlock. Include in the xml values ​​folder called "styles_mytheme.xml":

 <?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="Theme.Styled" parent="@style/Theme.Sherlock.Light"> <item name="actionBarStyle">@style/CustomActionBarStyle</item> <item name="android:actionBarStyle">@style/CustomActionBarStyle</item> <item name="android:actionBarItemBackground">@drawable/overflow_selector</item> <item name="android:itemBackground">@drawable/overflow_selector</item> <item name="android:actionBarWidgetTheme">@style/CustomActionOverflowDropDownText</item> <item name="actionBarWidgetTheme">@style/CustomTitleColorBar</item> <item name="android:icon">@drawable/ic_nav_home_back</item> <item name="android:homeAsUpIndicator">@drawable/ic_nav_back</item> <item name="icon">@drawable/ic_nav_home_back</item> <item name="dropDownListViewStyle">@style/DropDownStyles</item> <item name="android:dropDownListViewStyle">@style/DropDownStyles</item> </style> <style name="CustomActionBarStyle" parent="@style/Widget.Sherlock.ActionBar"> <!-- define background for action bar (sets default for all parts of action bar - main, stacked, split) --> <item name="android:background">@drawable/navigation</item> <item name="background">@drawable/navigation</item> <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item> <item name="titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item> </style> <!-- Style for the color title bar --> <style name="CustomTitleColorBar" parent="@style/TextAppearance.Sherlock.Widget.ActionBar.Title"> <item name="android:textColor">@color/white</item> <item name="android:textSize">12sp</item> </style> <style name="CustomActionOverflowDropDownText" parent="Widget"> <item name="android:textColor">@color/white</item> </style> <style name="MyTheme.ActionBar.TitleTextStyle" parent="@style/TextAppearance.Sherlock.Widget.ActionBar.Title"> <item name="android:textColor">@color/white</item> </style> <style name="My_Theme" parent="Theme.Sherlock"> <item name="android:popupMenuStyle">@style/MyApp.PopupMenuStyle</item> <item name="popupMenuStyle">@style/MyApp.PopupMenuStyle</item> </style> <style name="MyApp.PopupMenuStyle" parent="Widget.Sherlock.ListPopupWindow"> <item name="android:popupBackground">@drawable/navigation</item> </style> <style name="DropDownStyles" parent="Widget.Sherlock.ListView.DropDown"> <item name="android:divider">@null</item> <item name="android:listSelector">@drawable/overflow_selector</item> </style> </resources> 

Now include this code in the code:

 setTheme(Theme.Styled); 

Now change these three lines, when you change these three lines, the icon will change:

  <item name="android:icon">@drawable/ic_nav_home_back</item> <item name="android:homeAsUpIndicator">@drawable/ic_nav_back</item> <item name="icon">@drawable/ic_nav_home_back</item> 
0
source share
 if(getSupportActionBar() != null) { getSupportActionBar().setDisplayUseLogoEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setIcon(R.drawable.add_contact); } 
0
source share

All Articles