Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No App Icon on ActionBar

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.

enter image description here

I think it's supposed to be added by default that's why I can't add it through its XML

enter image description here

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!

like image 322
rsano Avatar asked Nov 03 '14 18:11

rsano


People also ask

How do I get my Android toolbar icon back?

Show back button using actionBar. setDisplayHomeAsUpEnabled(true) this will enable the back button. Custom the back event at onOptionsItemSelected. This will enable the back function to the button on the press.

How do I get the action bar?

You may otherwise add the action bar by calling requestFeature(FEATURE_ACTION_BAR) or by declaring it in a custom theme with the windowActionBar property. Beginning with Android L (API level 21), the action bar may be represented by any Toolbar widget within the application layout.

What is the difference between ActionBar and toolbar?

An Action bar is traditionally a part of an Activity opaque window decor controlled by the framework but a Toolbar may be placed at any level of nesting within a view hierarchy. The toolbar provides more feature than ActionBar . A Toolbar may contain a combination of elements from start to end.

How to get the icon at the start of the actionbar?

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. Share Improve this answer Follow edited Apr 10 '17 at 17:23

How to hide the action bar in Android app?

Another way to hide Action Bar is through Window Manager by setting the WindowManager flag. This approach makes it a lot easier to hide the Action Bar when the user interacts with your application. You can use the “setFlags” function as described below in the code. Also, you have to use flags before setContentView () of Activity.

Is it possible to add IC_launcher to Actionbar?

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. Share Improve this answer Follow edited Sep 25 '15 at 14:09

Should I use application icon plus title on my toolbars?

In modern Android UIs developers should lean more on a visually distinct color scheme for toolbars than on their application icon. The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer.


2 Answers

As of AppCompat version 21, the Action Bar follows the material design guidelines and uses a Toolbar:

  • A title and subtitle. The title should be a signpost for the Toolbar's current position in the navigation hierarchy and the content contained there. The subtitle, if present should indicate any extended information about the current content. If an app uses a logo image it should strongly consider omitting a title and subtitle.

In modern Android UIs developers should lean more on a visually distinct color scheme for toolbars than on their application icon. The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer.

However, if you want an application icon, setLogo() is the correct method.

like image 94
ianhanniballake Avatar answered Sep 24 '22 17:09

ianhanniballake


Update your onCreate() method with the code below.

 @Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     getSupportActionBar().setDisplayShowHomeEnabled(true);     getSupportActionBar().setLogo(R.drawable.ic_launcher);     getSupportActionBar().setDisplayUseLogoEnabled(true);     setContentView(R.layout.activity_main); } 

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.

like image 41
FalconHawk Avatar answered Sep 21 '22 17:09

FalconHawk