The application icon does not appear in the action bar (Android Studio 1.0.1)

So, I'm pretty new to Android development, and I just can't get ANY icon to display in the action bar.

I create a new project with a minimum sdk 15 API and select "Holo.Light" from the subject drop-down list (XML-Design-View).

So I want this to look like this: http://i.stack.imgur.com/zfgCq.png

but instead it looks like this: http://i.imgur.com/Lmxutct.png

My AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?> 

 <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> 

I think I need to change android: the theme for Holo.Light somehow? but theres no ressource are not defined and I cannot add any ..

my styles.xml:

 <resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"/> <!-- Customize your theme here. --> 

ic_launcher.png is in the drawables folder .. so what do I need to do to display this damn icon?

(I use my HTC one M8 btw, but it also does not appear on the emulator)

thanks!

+5
source share
2 answers

To display an icon on an ActionBar, you must add:

 getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setIcon(R.drawable.ic_launcher); 

in onCreate .

+15
source

Another way solved with this code

 ActionBar actionBar = getSupportActionBar(); actionBar.setLogo(R.drawable.ic_launcher); actionBar.setDisplayUseLogoEnabled(true); actionBar.setDisplayShowHomeEnabled(true); 
+1
source

Source: https://habr.com/ru/post/1210010/


All Articles