用于全方位视图的通用圆形按钮
Generic rounded button for all rouned view
I have created a rounded button like
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/theme_chocolate_level" />
<corners android:radius="20dp"/>
<padding android:bottom="12dp" android:left="12dp"
android:right="12dp" android:top="12dp"/>
</shape>
我必须使用 multiple rounded button
但所有颜色都不同。有没有一种 xml 方法可以为我的所有按钮使用一个通用的圆形按钮。否则我必须创建 多个可绘制对象并且只更改纯色属性
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rounded_generic_btn"
/>
我知道我可以通过编程来完成,但我非常有兴趣通过 xml 来完成。
我不想以编程方式进行。我知道那样
您可以在 xml 的视图中使用 backgroundTint attr 为背景着色。
由于此属性是在 API 21 中添加的,因此您需要使用自定义前缀对其进行设置。
在您的根视图中:xmlns:app="http://schemas.android.com/apk/res-auto"
然后在视图中:app:backgroundTint="@color/your_color"
I have created a rounded button like
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/theme_chocolate_level" />
<corners android:radius="20dp"/>
<padding android:bottom="12dp" android:left="12dp"
android:right="12dp" android:top="12dp"/>
</shape>
我必须使用 multiple rounded button
但所有颜色都不同。有没有一种 xml 方法可以为我的所有按钮使用一个通用的圆形按钮。否则我必须创建 多个可绘制对象并且只更改纯色属性
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rounded_generic_btn"
/>
我知道我可以通过编程来完成,但我非常有兴趣通过 xml 来完成。
我不想以编程方式进行。我知道那样
您可以在 xml 的视图中使用 backgroundTint attr 为背景着色。 由于此属性是在 API 21 中添加的,因此您需要使用自定义前缀对其进行设置。
在您的根视图中:xmlns:app="http://schemas.android.com/apk/res-auto"
然后在视图中:app:backgroundTint="@color/your_color"