This works for me with Theme.Light
android.support.v7.app.ActionBar menu = getSupportActionBar();
menu.setDisplayShowHomeEnabled(true);
menu.setLogo(R.drawable.ic_launcher);
menu.setDisplayUseLogoEnabled(true);
Question
The theme of my application is Light. Can I display app icon in action bar without changing app style from Theme.Light to Theme.Holo.Light.
style.xml
<style name="AppBaseTheme" parent="android:Theme.Light">
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:logo="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
The styles of "EditText" and etc object more beautiful with Theme.Light, that why I don't want to change it. It is possible or I should write style for each object and change theme of application.
Solution
This works for me with Theme.Light
android.support.v7.app.ActionBar menu = getSupportActionBar();
menu.setDisplayShowHomeEnabled(true);
menu.setLogo(R.drawable.ic_launcher);
menu.setDisplayUseLogoEnabled(true);
OTHER TIPS
The actionbar uses the android:logo attribute from manifest file. Then use setDisplayUseLogoEnabled() to set it in the ActionBar
Try like this
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME |
ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP |
ActionBar.DISPLAY_USE_LOGO);
getSupportActionBar().setIcon(R.drawable.search_icon);
getSupportActionBar().setDisplayUseLogoEnabled(true);
This works well for me:
//show the icon
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_launcher);