【问题标题】:Android 5.0 (Lollipop) CheckedTextView press highlight issuesAndroid 5.0 (Lollipop) CheckedTextView 按突出显示问题
【发布时间】:2014-12-17 05:51:43
【问题描述】:

在 Android 5.0 Lollipop 上运行时,RecyclerView 充满了CheckedTextViews,我遇到了一个令人沮丧的问题。 Lollipop 之前的所有版本都很好,不会出现此问题。请查看以下图片以更好地理解:

棒棒糖前

棒棒糖

看看 Lollipop 如何仅在 CheckedTextView 的复选框部分顶部绘制选择突出显示? Pre-Lollipop 没有这个问题/错误,并在视图的整个宽度上绘制选择突出显示(这是我想要的行为)。

这是我要绘制到列表中的 CheckedTextView:

<?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" />

有什么想法吗?我尝试了几种不同的解决方案,例如android:focusable="false"android:duplicateParentState="true"android:duplicateParentState="false"...

谢谢大家!

【问题讨论】:

    标签: android android-5.0-lollipop android-recyclerview checkedtextview


    【解决方案1】:

    您可以像在 Google IO 应用程序中一样使用 CheckBoxPreference 来解决这个问题,顺便说一下我想知道 CheckedTextView 中是否是棒棒糖问题。

    我尝试使用 backgroundselectablebordeless,但它也不起作用。

    你解决了吗还是一个已知的错误?

    编辑:

    您可以在checkedtextview 上使用framelayout,并使用带有framelayout 的onClickListener 来设置checktextview 的选中和取消选中。将 framelayout 和 checkedtextview 放在相对布局中:

              <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-21
      • 1970-01-01
      • 2013-11-14
      • 2015-05-13
      • 2015-10-04
      • 1970-01-01
      • 1970-01-01
      • 2014-12-18
      相关资源
      最近更新 更多