Show Icon in Actionbar/Toolbar with Appcompat-V7 21

show icon in actionbar/toolbar with AppCompat-v7 21

getSupportActionBar().setDisplayShowHomeEnabled(true);

along with

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

The application icon does not show on action bar

You are using the AppCompat version 21+ and it is normal.

The Action Bar follows the material design guidelines and uses a Toolbar.
As you can read here:

The use of application icon plus title as a standard layout is
discouraged on API 21 devices and newer.

If you would like an application icon (but I discourage it), you can use the method setLogo().

Something like this:

ActionBar actionBar = getSupportActionBar();
actionBar.setLogo(R.drawable.my_logo);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);

Logo are not displayed in Actionbar, using AppCompat

I removed all the android:logo attributes from my AndroidManifest.xml and I modified my MyActionBarLogo style like this:

<style name="MyActionBarLogo" parent="@style/Widget.AppCompat.Light.ActionBar">
<item name="background">@color/mainColor500</item>
<item name="logo">@drawable/actionbar_logo</item>
<item name="displayOptions">useLogo|showHome</item>
</style>

Now the actionbar is displaying my logo. :)

Drawer Indicator on ActionBar compat v7 21

You got that issue because you set (android:)homeAsUpIndicator in your theme. Remove that attribute will solve your problem.

Android actionbar icon

Try this code. Import v7.widget.Toolbar and extends AppCompatActivity

import android.support.v7.widget.Toolbar;

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setIcon(R.drawable.ic_statusbar_msg);


Related Topics



Leave a reply



Submit