Android - How to show App logo in action bar
Asked Answered
S

4

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.

Steamroller answered 23/10, 2013 at 11:40 Comment(0)
P
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);
Probity answered 6/3, 2015 at 17:32 Comment(0)
D
2

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

Desdemona answered 23/10, 2013 at 11:47 Comment(4)
When my application theme is "Theme.Light" and onCreate function I write getActionBar().setDisplayUseLogoEnabled(true); application crashes. Did I am right understand you?Steamroller
Is your code working with action bar without doing any logo related settings?Desdemona
If I write in theme this <style name="AppBaseTheme" parent="android:Theme.Holo.Light"> its displays logo too but whit theme which I don't want to have. And in this case I can write getActionBar().setDisplayUseLogoEnabled(true) too. I need to know if exist any way to display logo in action bar without changing Theme.Light theme to Theme.Holo.Light?Steamroller
does anyone know how in Kotlin?Sulla
W
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);
Wilbourn answered 9/2, 2018 at 7:20 Comment(0)
S
0

This works well for me:

//show the icon
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_launcher);
Spurling answered 14/1, 2020 at 22:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.