Home > Net >  Clip or mask selectableitembackground to textview background with rounded corner drawable
Clip or mask selectableitembackground to textview background with rounded corner drawable

Time:02-02

I want to clip the selectableitembackground ripple effect to the background in textview

code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/Primary"
    android:orientation="vertical"
    tools:context=".StickerPackInfoActivity">

    <TextView
        android:id="@ id/tray_icon"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="16dp"
        android:background="@drawable/rounded_16dp"
        android:backgroundTint="@color/PrimaryLight"
        android:gravity="center"
        android:padding="16dp"
        android:text="@string/info_screen_tray_icon"
        android:textColor="@color/Text"
        ads:drawableTint="@color/colorAccent"
        ads:drawableTopCompat="@drawable/info_vector" />


    <LinearLayout
        android:id="@ id/button_holder"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@ id/tray_icon"
        android:layout_centerHorizontal="true"
        android:layout_marginStart="16dp"
        android:layout_marginTop="40dp"
        android:layout_marginEnd="16dp"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@ id/view_webpage"
                android:layout_width="0dp"
                android:layout_height="80dp"
                android:layout_weight="0.5"
                android:background="@drawable/rounded_40dp"
                android:backgroundTint="@color/PrimaryLight"
                android:foreground="?android:attr/selectableItemBackground"
                android:gravity="center"
                android:padding="16dp"
                android:text="@string/view_webpage"
                android:textColor="@color/Text"
                ads:drawableTint="@color/colorAccent"
                ads:drawableTopCompat="@drawable/website_vector" />

            <TextView
                android:id="@ id/send_email"
                android:layout_width="0dp"
                android:layout_height="80dp"
                android:layout_marginStart="16dp"
                android:layout_weight="0.5"
                android:background="@drawable/rounded_40dp"
                android:backgroundTint="@color/PrimaryLight"
                android:foreground="?android:attr/selectableItemBackground"
                android:gravity="center"
                android:padding="16dp"
                android:text="@string/send_email"
                android:textColor="@color/Text"
                ads:drawableTint="@color/colorAccent"
                ads:drawableTopCompat="@drawable/email_vector" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:orientation="horizontal">


            <TextView
                android:id="@ id/license_agreement"
                android:layout_width="0dp"
                android:layout_height="80dp"
                android:layout_weight="0.5"
                android:background="@drawable/rounded_40dp"
                android:backgroundTint="@color/PrimaryLight"
                android:foreground="?android:attr/selectableItemBackground"
                android:gravity="center"
                android:padding="16dp"
                android:text="@string/license_agreement"
                android:textColor="@color/Text"
                ads:drawableTint="@color/colorAccent"
                ads:drawableTopCompat="@drawable/agreement_vector" />

            <TextView
                android:id="@ id/privacy_policy"
                android:layout_width="0dp"
                android:layout_height="80dp"
                android:layout_marginStart="16dp"
                android:layout_weight="0.5"
                android:background="@drawable/rounded_40dp"
                android:backgroundTint="@color/PrimaryLight"
                android:foreground="?android:attr/selectableItemBackground"
                android:gravity="center"
                android:padding="16dp"
                android:text="@string/privacy_policy"
                android:textColor="@color/Text"
                ads:drawableTint="@color/colorAccent"
                ads:drawableTopCompat="@drawable/privacy_vector" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:orientation="horizontal">

            <TextView
                android:id="@ id/rate_app"
                android:layout_width="0dp"
                android:layout_height="80dp"
                android:layout_weight="0.5"
                android:background="@drawable/rounded_40dp"
                android:backgroundTint="@color/PrimaryLight"
                android:foreground="?android:attr/selectableItemBackground"
                android:gravity="center"
                android:padding="16dp"
                android:text="@string/rate_app"
                android:textColor="@color/Text"
                ads:drawableTint="@color/colorAccent"
                ads:drawableTopCompat="@drawable/rate_us_vector" />

            <TextView
                android:id="@ id/how_to_remove"
                android:layout_width="0dp"
                android:layout_height="80dp"
                android:layout_marginStart="16dp"
                android:layout_weight="0.5"
                android:background="@drawable/rounded_40dp"
                android:backgroundTint="@color/PrimaryLight"
                android:foreground="?android:attr/selectableItemBackground"
                android:gravity="center"
                android:padding="16dp"
                android:text="@string/help"
                android:textColor="@color/Text"
                ads:drawableTint="@color/colorAccent"
                ads:drawableTopCompat="@drawable/question_vector" />

        </LinearLayout>

    </LinearLayout>

    <com.google.android.gms.ads.AdView
        android:id="@ id/adView"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:background="@color/Primary"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_id" />


</RelativeLayout>

screenshots of current situation: https://i.stack.imgur.com/YWsIt.png

It looks kind of ugly when textview is clicked. how can it be fixed within the xml?

CodePudding user response:

Create a custom drawable like this and set it to background

<?xml version="1.0" encoding="UTF-8"?>
<ripple
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="#colorHex">
    <item android:drawable="@drawable/drawableName"/>
</ripple>

Also remove the foreground value:
android:foreground="?android:attr/selectableItemBackground"

  •  Tags:  
  • Related