Change homeAsUpIndicator dynamically

I create an application with four tabs and, as a result, four fragments. In the first fragment, I have a sliding menu, and I drop using the icon in the action bar. The problem is that in the remaining fragments, I want to create another custom icon to return to the first fragment, but I do not know what to do ...

This is my .xml style with my custom icon for the sliding menu:

<!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <item name="android:homeAsUpIndicator">@drawable/menu32</item>
    </style>

Java code works well, but I don't know how to change the icon dynamically.

This is what I have:

wDu0j.png

0
source share
1 answer

In your snippets you can use the following:

Actionbar ab = getActivity().getActionBar();
ab.setIcon(icon);

icon - Drawable resource, .
setHomeAsUpIndicator, API > 11:

getActivity().getActionBar().setHomeAsUpIndicator(resId);

API , ActionbarSherlock.

+1

All Articles