如何使用布局作为背景来设置按钮的背景色

问题描述

layout_bg.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#FFFFFF"/>
    <!--<stroke android:width="3dp" android:color="#B1BCBE" />-->
    <corners android:radius="10dp"/>
    <padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>

main_activity.xml

<ImageButton
            android:background="@drawable/layout_bg"
            android:src="@drawable/myicon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:tint="@android:color/black"
            android:minWidth="80.0dp"
            android:minHeight="80.0dp"
            android:padding="10px"
            android:scaleType="fitCenter"
            android:layout_alignParentBottom="true"
            android:id="@+id/btnFoo"
            android:layout_marginLeft="91.0dp" 
           />

我正在将ImageButton的背景设置为布局,这样我就可以拥有动态圆角,如您在此图中看到的那样:

enter image description here

但是,我需要将按钮的背景色更改为另一种纯色,例如红色。

如果我用btnFoo.SetBackgroundColor(Color.Red)设置背景色,则圆角消失了。

我认为是因为它将背景属性改写为纯色值而不是layout_bg.xml文件。

如何设置此特定ImageButton的背景颜色,而不是main_activity中并非所有以layout_bg为背景的ImageButton的背景颜色?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)