简体   繁体   中英

android TextView background drawable not affect

I have a custom textview.I am using app:background drawable because of backward compatibility.(in app gradle I have defined vectorDrawables.supportlibrary = true).But my code xml definition does not affect background of textview.

  <mobi.appcent.studioandroidapp.customView.GradientTextView
            android:id="@+id/btnGoToMainPage"
            android:layout_marginBottom="25dp"
            app:background="@drawable/ic_btn_pink"
            android:text="@string/go_to_main_page"
            android:textColor="@color/white"
            android:gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="16dp"
            android:fontFamily="@font/sf_pro_display_regular"
            android:lineSpacingExtra="2sp"
            android:layout_centerHorizontal="true"
            android:layout_below="@+id/ivIcon"
            android:textSize="17sp"
            app:firstColor="@color/pink_orange"
            app:secondColor="@color/light_salmon_pink"
            android:textAllCaps="false"
            android:visibility="visible" />

You can use this textview

<androidx.appcompat.widget.AppCompatTextView
            android:id="@+id/btnCancel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:background="@drawable/btn_round"
            android:gravity="center"
            android:padding="8dp"
            android:text="@string/str_cancel"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="14sp""
            app:textAllCaps="true" />

btn_round.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item><shape>
        <stroke android:width="1dp" android:color="@color/colorPrimaryDark" />

        <solid android:color="@android:color/transparent" />

        <corners
                android:radius="500dp"/>

    </shape></item>

</selector>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM