简体   繁体   English

android TextView 背景可绘制不影响

[英]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. 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你可以使用这个 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 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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