V
V
Vanes Ri_Lax2015-06-17 15:51:46
Android
Vanes Ri_Lax, 2015-06-17 15:51:46

How to put logo in ActionBar?

Hello, I'm doing an ActionBar following the example here , everything seems to work, but I can't display the logo.
I wrote in the manifest like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ru.test.myapplication" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/logo_icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"

       >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:logo="@mipmap/logo_icon"
           >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Here is the Java code:
package ru.test.myapplication;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends ActionBarActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

Here is the menu_main.xml code:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:sabd="http://schemas.android.com/apk/res-auto" >
    <item
        android:id="@+id/action_settings"
        android:title="@string/action_settings"
        android:icon="@android:drawable/ic_menu_call"
        sabd:showAsAction="always" />
  
</menu>

As a result, I get this:
0c7145fee2d3473d87552a24bd5e592b.JPG
And I need to put a logo instead of an inscription.
What am I doing wrong?
Thank you very much in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Emin, 2015-06-17
@Ewintory

Activity.getSupportActionBar().setIcon(getDrawable(R.mipmap.logo));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question