gpt4 book ai didi

java - 如何将可绘制集的背景/颜色更改为 View 的背景?

转载 作者:数据小太阳 更新时间:2023-10-29 02:50:55 25 4
gpt4 key购买 nike

我的 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>

我基本上使用它为我将其设置为背景的任何 View 设置圆角。但我想知道的是如何使该 View 的颜色/背景色调保持动态。因为可以说我有三个 View 都需要圆角但都需要不同的颜色,所以此时我必须创建三个不同的可绘制文件并分别为每个文件设置颜色。正如我在上面的文件中所做的那样。我试过在原始 View 上使用 BackgroundTint,但它不起作用。

最佳答案

GradientDrawable background = (GradientDrawable) textView.getBackground();
background.setColor(getResources().getColor(R.color.some_color));

我认为您已将可绘制的形状应用到 textView 作为背景。

因此,您需要使用设置了背景的 View 来获取背景。

关于java - 如何将可绘制集的背景/颜色更改为 View 的背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47975581/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com