1
votes

I'm trying to set the navigationIcon to display a back arrow in the toolbar using Appcompat 21. My themes.xml inside the folder values-v21 looks like this:

<style name="AppTheme" parent="AppTheme.Base" />

<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
    <item name="android:colorPrimary">@color/primary</item>
    <item name="android:colorPrimaryDark">@color/primary_dark</item>

    <item name="android:dropDownListViewStyle">@style/DropDownListViewStyle</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:navigationIcon">@drawable/abc_ic_ab_back_holo_light</item>
    <item name="android:navigationContentDescription">@string/navigation_content_description</item>

To which I receive the error:

error: Error: No resource found that matches the given name 
(at 'android:navigationIcon' with value '@drawable/abc_ic_ab_back_holo_light').

However if I ctrl-B (goto declaration) on the drawable it shows it located within the Appcompat library. Do I need to copy the drawable from the Appcompat into my local R drawable folder in order to use it or is there some way of getting Android Studio to understand that it should take it from there when it compiles?

1
I wasnt able to do this with a theme, but at least so far one workaround is to do: setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true);Jon

1 Answers

0
votes

Do this way :

<style name="AppTheme" parent="AppTheme.Base" >
</style>

 <style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
   <item name="android:colorPrimary">@color/primary</item>
   <item name="android:colorPrimaryDark">@color/primary_dark</item>
   <item name="android:dropDownListViewStyle">@style/DropDownListViewStyle</item>
   <item name="windowActionBar">false</item>
   <item name="android:windowNoTitle">true</item>

   <!-- Add below line to style arrow -->
   <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
 </style>

 <!-- Style arrow -->
 <style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <!-- this will set your arrow color -->
    <item name="color">@android:color/black</item>

    <!-- You can customize other stuff too -->
    <item name="spinBars">true</item>
    <item name="thickness">3dp</item>
    <item name="barSize">21dp</item>
    <item name="drawableSize">48dp</item>

 </style>     

It is working for me this way. Hope this helps ...