Search code examples
javaandroidandroid-actionbar

Add icon in Theme.AppCompat.Light


I'm using the Theme.AppCompat.Light in my android application and I would like to add an icon on the top left of the action bar. How can I do it? This is my Android Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.progettoium">
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.AppCompat.Light">
    <activity android:name=".ListaPrenotazioni"></activity>
    <activity android:name=".ListaCorsi" />
    <activity android:name=".ListaLiberi" />
    <activity
        android:name=".LoginSignup"
        android:label="@string/title_activity_login_signup"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity
        android:name=".Signup"
        android:theme="@style/AppTheme.NoActionBar" />
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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


Solution

  • you can add it programmatically with

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_action_refresh);
    

    in your main activity