Search code examples
androidtextviewandroid-cardviewcardview

Highlighted text in CardView has no color


I have a TextView inside a Cardview. The TextView has the property android:textIsSelectable="true", so I am able to highlight text. The problem is that there is no color to the highlight. Setting android:textColorHighlight did not work either.


Solution

  • I am able to see selected colour using textIsSelectable="true" and "textColorHighlight" attributes. Here is my code:

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

    enter image description here