Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

com.android.support:design:24.1.0 didn't display correctly in navigation bar

I have updated my dependencies to the following:

com.android.support:design:24.0.0 --> com.android.support:design:24.1.0 com.android.support:appcompat-v7:24.0.0 --> com.android.support:appcompat-v7:24.1.0

I updated as well the build tools to version 24.0.1.

However after that, my navigation drawer looks not good, as you can see here:

With the old version it looks like that:

Do you have any idea what this error is or it is the new standard?

Thanks for every response.

like image 447
Julian Schmuckli Avatar asked Jul 19 '16 17:07

Julian Schmuckli


1 Answers

It seems it's a bug in new android support design library, check this thread in AOSP issue tracker, as mentioned there is a bug with checked item background - it uses colorPrimaryDark.

Until it would be fixed I've found probably ugly and maybe irrelevant in the future, but simple workaround - NavigationView uses colorPrimaryDark to highlight item background, so we can just override its android:theme with changed colorPrimaryDark to the one that we need, in our case it's gray.

So, firstly add a new style to your styles.xml:

<style name="NavigationViewGraySelectorTheme" parent="AppTheme">
    <!-- Extract this color to colors.xml -->
    <item name="colorPrimaryDark">#ddd</item>
</style>

And then simply use it in your NavigationView widget:

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    android:theme="@style/NavigationViewGraySelectorTheme"
    app:headerLayout="@layout/nav_header_main"
    app:itemIconTint="@color/nav_view_icon_color"
    app:itemTextColor="@color/nav_view_text_color"
    app:menu="@menu/activity_main_drawer"/>

UPDATE:

As Chris Banes mentioned in the AOSP issue thread, the issue will be fixed with the 24.1.1 version of support library release.

like image 104
romtsn Avatar answered Oct 18 '22 06:10

romtsn