Sinigami
Sinigami

Reputation: 449

ActionBar: How to set home home_as_up_indicator correctly?

I tried to set cusom drawable as home_as_up_indicator in styles, but instead of it displayed default action bar arrow. My code:

activity:

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

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

style:

<style name="MyTheme" parent="Theme.AppCompat">
    <item name="android:homeAsUpIndicator">@drawable/home_as_up_indicator</item>
</style>

manifest:

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/MyTheme" >
<activity
    android:name=".MainActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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

P.S.: It works only if to set home indicator in code but it is not satisfied me:

getSupportActionBar().setHomeAsUpIndicator(R.drawable.home_as_up_indicator);

Upvotes: 0

Views: 265

Answers (2)

Paresh
Paresh

Reputation: 6857

pretty simple. Use the below line of code :)

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

Upvotes: 0

Santhakumar
Santhakumar

Reputation: 26

Can you try the below code

<style name="MyTheme" parent="parent="@style/Theme.Sherlock.Light">
    <item name="android:homeAsUpIndicator">@drawable/home_as_up_indicator</item>
    <item name="homeAsUpIndicator">@drawable/home_as_up_indicator</item>
</style>

If it is not working then could you provide the your targetSdkVersion and minSDKVersion which mentioned in the AndroidManifest file. It may helpful for more analysis.

Upvotes: 1

Related Questions