Jhonycage
Jhonycage

Reputation: 859

Action Bar Logo not displaying

this issue is literally driving me crazy, I've been reading and looking for solutions everywhere and still I am not able to put a custom logo on the Action Bar, I can put background and other features but no logo, I'll put some of the code here, by the way, in the layout designer when i put them "holo light dark action bar" I can see the logo but when I run the app, it never shows up :

Android Manifest:

<application
    android:allowBackup="true"
    android:icon="@drawable/icon_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Activities.ItemManagerActivity"
        android:logo="@drawable/icon_launcher"
        android:label="@string/title_activity_item_manager" >
    </activity>
    <activity
        android:name=".Activities.MainActivity"
        android:icon="@drawable/icon_launcher"
        android:theme="@style/CustomActionBarTheme"
        android:label="@string/title_activity_main" >
    </activity>

MainActivity:

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    android.support.v7.app.AppCompatActivity actionBar;
    //getSupportActionBar().setIcon(R.drawable.icon_launcher);
    getSupportActionBar().setTitle("");
    getSupportActionBar().setDisplayUseLogoEnabled(true);
    getSupportActionBar().setLogo(R.drawable.icon_launcher);

styles.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:logo">@drawable/icon_launcher</item>
    <!-- Customize your theme here. -->
</style>

<style name="CustomActionBarTheme"
    parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/MyActionBar</item>

    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<!-- ActionBar styles -->
<style name="MyActionBar"
    parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:logo">@drawable/icon_launcher</item>

    <!-- Support library compatibility -->
    <!--<item name="background">@drawable/profile_banner_orange</item>-->
</style>

Upvotes: 2

Views: 2864

Answers (5)

tushar
tushar

Reputation: 335

Try this

    getSupportActionBar().setDisplayShowHomeEnabled(true);

    getSupportActionBar().setDisplayUseLogoEnabled(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
    {
        getSupportActionBar().setLogo(getDrawable(R.drawable.actionbar_logo));
    }
    else
        {
        getSupportActionBar().setLogo(getResources().getDrawable(R.drawable.actionbar_logo));
        }

if you want to include Navigation drawer button also include this line

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

Upvotes: 0

Androider
Androider

Reputation: 3873

actionBar.setDisplayShowHomeEnabled(false);

OR

actionBar.setHomeButtonEnabled(false);

Upvotes: 1

Kaveesh Kanwal
Kaveesh Kanwal

Reputation: 1763

Do it this way:

Add your item in the your menu xml file:

<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=".YourActivity">

<item android:id="@+id/your_id"
    android:icon="@drawable/your_icon"
    app:showAsAction="always"
    android:title="@string/your_title"
    />

</menu>

In your activity, override the onCreateOptionsMenu():

MenuItem your_menu;
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.your_menu_name, menu);
        your_menu = menu.findItem(R.id.your_id);
        return true;
    }

Hope the above description helps. Thanks.

Upvotes: 0

SagePawan
SagePawan

Reputation: 364

This should do

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

But dont forget to add

getSupportActionBar().setDisplayShowHomeEnabled(true);

Along with it

Upvotes: 3

Marko
Marko

Reputation: 20513

Try to use

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

Upvotes: 2

Related Questions