There are a lot of queries here about adding icons to ActionBar but none solved my problem. If you know a duplicate of this question, feel free to comment or close this question.
I migrated my project to IntelliJ and I didn't encounter this problem with my previous IDE (Eclipse).
PROBLEM: The app icon is not displayed in the ActionBar.
I think it's supposed to be added by default that's why I can't add it through its XML
Here's its XML
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity" >
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
app:showAsAction="always" />
</menu>
Thanks!
It really works. Try this.. Include these lines to your onCreate method,
Also, make sure that jerry is a .png image file available under mipmap folder. To get the icon exactly at the start of your action bar, have jerry file in all screen sizes like (hdpi, mdpi, xhdpi, xxhdpi, xxxhdpi etc) in mipmap folder.
Setting Icon On the Action Bar
Showing Icon On the Action Bar Can Easily trick any developer in trouble. Keep in Mind this Simple Method and it will never make you in trouble.
If Your
activity
is extending Activity,If Your
activity
is extending AppCompatActivity,It always work for us,Keep it in Mind.
As of AppCompat version 21, the Action Bar follows the material design guidelines and uses a Toolbar:
However, if you want an application icon, setLogo() is the correct method.
IN Style.xml
In activity add this and try
If you don't care about the Material theme and are fine having an Activity that looks more JellyBean/Kitkat style and includes the icon in the Action Bar, you can do the following:
First, change themes setting in styles.xml from this:
To this:
Now change all your Activities to inherit from android.app.Activity instead of android.support.v7.app.ActionBarActivity. That is:
Change this:
To this:
The end of result of doing both of the above steps is that the icon as specified by the android:icon attribute in AndroidManifest.xml will appear in the Action Bar.
Update your onCreate() method with the code below.
It worked for me. note: ic_launcher is the icon you want to display in your actionbar, for that you will have to add the icon in the drawable folder of your app project.