I tried a new toolbar component and had some problems with the navigation icon. I want to implement a custom icon for reverse navigation:
In my manifest, I set the parent for my activity:
<activity android:name=".CardsActivity" android:parentActivityName=".MainActivity"> <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".MainActivity" /> </activity>
I declare the toolbar as follows:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" tools:context="com.example.lollitest.MainActivity" > <android.support.v7.widget.Toolbar android:id="@+id/my_awesome_toolbar" android:layout_height="wrap_content" android:layout_width="match_parent" android:minHeight="?attr/actionBarSize" android:layout_marginBottom="10dp" android:background="?attr/colorPrimary" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/my_awesome_toolbar" android:text="@string/hello_world" /> </RelativeLayout>
Then, in my work, I customize the toolbar as follows:
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar); toolbar.setNavigationIcon(R.drawable.ic_good); toolbar.setTitle("Title"); toolbar.setSubtitle("Sub"); toolbar.setLogo(R.drawable.ic_launcher); setSupportActionBar(toolbar);
Which gives me: 
The back icon is not the one I set with setNavigationIcon() ! No matter what I can give the method, the navigation icon is always a back arrow.
I tried to remove the parent association in the manifest, but the only effect (obviously) is to prevent the button from returning.
Otherwise, if I want the default back arrow icon and don't call setNavigationIcon() , I donโt have the icon at all.
What is the correct way to handle the navigation icon in the toolbar (custom and default)?
NOte: I run my test on Android 4.4
android material-design appcompat toolbar android-actionbar-compat
grunk Oct 23 '14 at 9:37 2014-10-23 09:37
source share