9

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Anamnisis
  • 133
  • 1
  • 1
  • 7

4 Answers4

12

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);
Jim109
  • 501
  • 6
  • 14
2

The actionbar uses the android:logo attribute from manifest file. Then use setDisplayUseLogoEnabled() to set it in the ActionBar

Red Devil
  • 349
  • 4
  • 16
  • When my application theme is "Theme.Light" and onCreate function I write getActionBar().setDisplayUseLogoEnabled(true); application crashes. Did I am right understand you? – Anamnisis Oct 23 '13 at 11:59
  • Is your code working with action bar without doing any logo related settings? – Red Devil Oct 25 '13 at 02:20
  • If I write in theme this ` – Anamnisis Oct 26 '13 at 20:45
  • does anyone know how in Kotlin? – Louis Sankey Mar 03 '21 at 02:20
0

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);
Teja
  • 787
  • 7
  • 21
0

This works well for me:

//show the icon
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_launcher);
larsaars
  • 2,065
  • 3
  • 21
  • 32