Search code examples
androidxmlmanifest

how to set an icon in title bar including with name of the app


how to set an icon in title bar including with name of the app

here it looks like

but, I need to add an icon before Sample Text in title please help me

<application
    android:allowBackup="true"
    android:label="@string/app_name"
    android:icon="@drawable/coffee_cup"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity"
        android:icon="@drawable/coffee_cup"
        android:label="@string/app_name">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

no use is there any dependencies if so tell me, please


Solution

  • Answer is very simple no need of XML code it's a matter of 3 lines of java code in MainActivity,

    import this line inside MainActivity.java

    import android.support.v7.app.ActionBar;
    

    inside Create Method

     ActionBar actionBar = getSupportActionBar();
     actionBar.setDisplayShowHomeEnabled(true);
     actionBar.setIcon(R.mipmap.icon_launcher);