gpt4 book ai didi

android - 更改带边框的按钮背景

转载 作者:太空狗 更新时间:2023-10-29 16:12:24 25 4
gpt4 key购买 nike

我创建了一个带边框的按钮:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<solid android:color="#FFFFFFFF" />

<stroke
android:width="1dp"
android:color="#FFCCCCCC" />
</shape>

<Button
android:text="@null"
android:stateListAnimator="@null"
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/colorButton"
android:background="@drawable/button_border" />

现在我以编程方式更改背景的颜色。问题是一旦我更改背景,边框就会被删除。有没有办法改变按钮的背景颜色并保持边框?

最佳答案

试试这个,

    Button colorButton = (Button) findViewById(R.id.colorButton);
GradientDrawable background = (GradientDrawable) colorButton.getBackground();
background.setColor(getResources().getColor(R.color.some_color));

关于android - 更改带边框的按钮背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42551882/

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