Android 5.0 (Lollipop) CheckedTextView press highlight issues

777 views Asked by At

I'm having a frustrating issue with a RecyclerView filled with CheckedTextViews when running on Android 5.0 Lollipop. All versions before Lollipop are fine and don't exhibit this issue. Check out the pictures below for a better understanding:

Pre-Lollipop

pre-lollipop screenshot

Lollipop

lollipop screenshot

See how Lollipop only draws the selection highlight on top of just the checkbox part of the CheckedTextView? Pre-Lollipop doesn't have this issue / bug, and draws the selection highlight across the entire width of the view (which is the behavior that I want).

Here is the CheckedTextView that I'm drawing to the list:

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="?attr/selectableItemBackground"
    android:checkMark="@drawable/checkbox"
    android:id="@+id/model_checkable_name"
    android:layout_height="48dp"
    android:layout_width="match_parent" />

Any ideas? I've tried a handful of various different solutions, such as android:focusable="false", android:duplicateParentState="true", android:duplicateParentState="false"...

Thanks guys!

1

There are 1 answers

0
JavierSegoviaCordoba On

You can use, like in Google IO app, CheckBoxPreference to solve this, by the way I want to know if is a Lollipop issue in CheckedTextView.

I tried using backgroundselectablebordeless and it doesnt work too.

Do you solved it or is a known bug?

EDIT:

You can use a framelayout over the checkedtextview and use onClickListener with the framelayout to set checked and unchecked the checktextview. Put the framelayout and the checkedtextview inside of a relative layout:

          <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="56dp"
                android:layout_marginEnd="8dp"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="8dp"
                android:layout_marginStart="8dp">

                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_alignParentBottom="true"
                    android:layout_marginTop="8dp"
                    android:background="@color/md_divider" />

                <android.support.v7.widget.SwitchCompat
                    android:id="@+id/switchWidget"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:padding="16dp"
                    android:text="Switch Widget Title"
                    android:textAppearance="@style/TextAppearance.AppCompat.Inverse"
                    android:textColor="@color/md_text"
                    android:textSize="16sp" />

                <FrameLayout
                    android:id="@+id/frameLayoutSwitch"
                    android:clickable="true"
                    android:background="?attr/selectableItemBackground"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"/>
            </RelativeLayout>