Skip to content

[TabLayout] tabRippleColor ignores focused state value #2434

@ryan-w

Description

@ryan-w

Description: When providing a color state list to the tabRippleColor property of the TabLayout control, only the selected state state_selected and pressed state state_pressed are observed. The focused state state_focused is ignored.

Here is the code that restricts the color state list:

// So we only allow two base states: selected, and non-selected. For each base state, we only

That is referenced here:

RippleUtils.convertToRippleDrawableColor(tabRippleColorStateList);

This runs counter to the documentation and the default color state list provided by Material.
https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/tabs/res/color/mtrl_tabs_ripple_color.xml

Expected behavior: Color state list items that set the focused state to true android:state_focused="true" should be selected when the tab item is focused.

Source code:

With the example code below, when you use the keyboard to focus one of the tab items, the background color is red, but it should be green.

File Name: tabs_ripple.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:alpha="0.30" android:color="#00ff00" android:state_focused="true"/>
    <item android:alpha="0.30" android:color="#ff0000" />
</selector>
<com.google.android.material.tabs.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabRippleColor="@color/tabs_ripple">

    <com.google.android.material.tabs.TabItem
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Item 1"/>

    <com.google.android.material.tabs.TabItem
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Item 2"/>

    <com.google.android.material.tabs.TabItem
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Item 3"/>

</com.google.android.material.tabs.TabLayout>

Android API version: 30

Material Library version: 1.4.0

Device: Multiple

To help us triage faster, please check to make sure you are using the latest version of the library.

We also happily accept pull requests.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions