Bug 39438 - NavigationView state_checked background selector ignored
Summary: NavigationView state_checked background selector ignored
Status: RESOLVED NORESPONSE
Alias: None
Product: Android
Classification: Xamarin
Component: General (show other bugs)
Version: 6.0.99
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2016-03-08 09:42 UTC by Ryan
Modified: 2017-10-04 15:19 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NORESPONSE

Description Ryan 2016-03-08 09:42:54 UTC
I'm running into a problem that seems to have been a known bug in previous versions of the support library but is meant to have been fixed. I wonder if it's now affecting Xamarin only for some reason. I have the latest support packages from the SDK manager and Nuget Support.Design package is at 23.1.1.1

I'm trying to use a drawable selector to set a custom background for the current item in a NavigationView. However the state_checked selector item is ignored completely (state_pressed works fine).

An example of the problem can be seen here http://stackoverflow.com/questions/31208179/appitembackground-attribute-doesnt-work-as-expected

And on the Android issue tracker here https://code.google.com/p/android/issues/detail?id=178697

Layout:

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_height="match_parent"
    android:layout_width="wrap_content"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header"
    app:menu="@menu/drawer_view"
    app:itemBackground="@drawable/state_list_drawer_background" />

and selector:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Checked state (this one is the problem and never gets used) -->
    <item android:drawable="@drawable/background_checked" android:state_checked="true" />
    <!-- This is the default background color -->
    <item android:drawable="@drawable/background_normal" />
</selector>
Comment 1 Ryan 2016-08-10 11:51:43 UTC
Hi, has there been any movement on this? We have delayed implementing a custom menu for the run of the project, but we have to deliver in a couple of weeks so we need to come up with a solution soon.

Thanks for your help,
Ryan
Comment 2 Jon Douglas [MSFT] 2016-08-15 16:04:03 UTC
Hi Ryan,

I don't believe this is a bug in the Xamarin Support Design Library(https://www.nuget.org/packages/Xamarin.Android.Support.Design/) as it seems to work on my end just fine.

Here's my selector named "navigationstate.xml" with the following code based on your example:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <!-- Checked state (this one is the problem and never gets used) -->
  <item android:drawable="@drawable/cheese_1" android:state_checked="true" />
  <item android:drawable="@drawable/cheese_2" android:state_pressed="true" />
  <item android:drawable="@drawable/cheese_3" android:state_activated="true" />
  <!-- This is the default background color -->
  <item android:drawable="@drawable/icon" />
</selector>

I used this repo below to try and reproduce as it already had the key items built into it:

https://github.com/xamarin/monodroid-samples/tree/master/android5.0/Cheesesquare

Now the only thing to do was to add the selector from above to the NavigationView:

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/drawer_view"
        app:itemBackground="@drawable/navigationstate"
        />

After this, it seems that the respective "cheese_1" drawable is being displayed as the "state_checked" state here.

http://screencast.com/t/xkj0uYCg

Here's my packages.config as well for reference:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="23.4.0.1" targetFramework="monoandroid50" />
  <package id="Xamarin.Android.Support.Design" version="23.4.0.1" targetFramework="monoandroid50" />
  <package id="Xamarin.Android.Support.v4" version="23.4.0.1" targetFramework="monoandroid50" />
  <package id="Xamarin.Android.Support.v7.AppCompat" version="23.4.0.1" targetFramework="monoandroid50" />
  <package id="Xamarin.Android.Support.v7.CardView" version="23.4.0.1" targetFramework="monoandroid50" />
  <package id="Xamarin.Android.Support.v7.RecyclerView" version="23.4.0.1" targetFramework="monoandroid50" />
  <package id="Xamarin.Android.Support.Vector.Drawable" version="23.4.0.1" targetFramework="monoandroid50" />
</packages>

Do you have a sample in which these conditions are not working for you? It seems to work out of the box on this end.
Comment 3 Ryan 2016-08-15 16:36:44 UTC
Hi Jon,

Thanks for getting back to me, i'll see if I can find out.
Comment 4 Jon Douglas [MSFT] 2017-10-04 15:19:40 UTC
Because we have not received a reply to our request for more information we are closing this issue. If you are still encountering this issue, please reopen the ticket with the requested information. Thanks!