【问题标题】:Highlighted text in CardView has no colorCardView 中突出显示的文本没有颜色
【发布时间】:2021-12-04 00:33:43
【问题描述】:

我在 Cardview 中有一个 TextView。 TextView 具有属性android:textIsSelectable="true",因此我可以突出显示文本。问题是高光没有颜色。设置android:textColorHighlight 也不起作用。

【问题讨论】:

    标签: android textview android-cardview cardview


    【解决方案1】:

    我可以使用 textIsSelectable="true" 和 "textColorHighlight" 属性查看所选颜色。这是我的代码:

    <com.google.android.material.card.MaterialCardView
        android:id="@+id/mainCard"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardElevation="2dp"
        app:layout_constraintTop_toTopOf="parent">
        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TextView
              android:id="@+id/textView"
              app:layout_constraintStart_toStartOf="parent"
              app:layout_constraintEnd_toEndOf="parent"
              app:layout_constraintTop_toTopOf="parent"
              android:text="This is a Text View"
              android:textColorHighlight="#ff00ff"
              android:textIsSelectable="true"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" />
        </androidx.constraintlayout.widget.ConstraintLayout>
    </com.google.android.material.card.MaterialCardView>
    

    【讨论】:

    • 你是对的。我在代码的其他地方以编程方式将 highlightColor 设置为透明。谢谢!
    猜你喜欢
    • 2010-10-18
    • 2016-03-29
    • 2014-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多