我的drawables文件夹中有这个xml 。
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp"/>
<solid android:color="#ffffff"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
我基本上是用它来为我设置为背景的任何视图添加圆角。但是我想知道的是如何使该视图的颜色/背景色调保持动态。因为可以说我有都需要它,圆角的,但都需要不同的颜色,在一分钟,我不必单独创建三个不同的绘制文件,并设置颜色为每个文件的三个视图。正如我在上面的文件中所做的。我已经尝试BackgroundTint在原始视图上使用,但是它不起作用。
GradientDrawable background = (GradientDrawable) textView.getBackground();
background.setColor(getResources().getColor(R.color.some_color));
Run Code Online (Sandbox Code Playgroud)
我认为您已将可绘制形状应用于textView作为背景。
因此,您需要使用已设置背景的视图来获取背景。
| 归档时间: |
|
| 查看次数: |
962 次 |
| 最近记录: |