gpt4 book ai didi

Android:使用定义的可绘制对象以编程方式更改按钮颜色

转载 作者:太空狗 更新时间:2023-10-29 15:09:57 24 4
gpt4 key购买 nike

我有:

public Button[] getButtons(int buttonCount, List<String> buttonHeaders, Context activity) {
Button[] result = new Button[buttonCount];

for (int i = 0; i < buttonCount; i++) {

result[i] = new Button(activity);

result[i].setId(i);
result[i].setText(buttonHeaders.get(i));
result[i].setBackgroundResource(R.drawable.buttons_shape);
result[i].setBackgroundColor(randomColor(activity));
result[i].setTextColor(activity.getResources().getColor(R.color.white));
result[i].setWidth(360);
result[i].setHeight(100);
}
return result;
}

但在我的可绘制对象中是:

 <solid android:color="@color/white"/> 
<corners
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>

但是我想给程序定义什么颜色,因为颜色是随机的,当我改变背景时又回到默认设计(PS。对不起英文:P)

最佳答案

你不能两者都做..要么你可以做 view.setBackgroundDrawable(drawable);或 view.setBackGroundColor(color);

关于Android:使用定义的可绘制对象以编程方式更改按钮颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17700096/

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