我在drawable文件夹中有xml文件,用于圆形按钮 - rounded.xml.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ccc" />
<corners android:radius="5dp" />
<stroke android:width="1dp" android:color="#000" />
</shape>
Run Code Online (Sandbox Code Playgroud)
通常我使用android:background = "@drawable/rounded"内部按钮xml 设置它,但我想创建几个不同颜色的xml文件,以便我可以更改应用程序主题.
你知道我应该如何为按钮设置背景,但在java中?
这应该工作:
Button button = (Button) findViewById(R.id.myButton);
button.setBackgroundResource(R.drawable.rounded);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2917 次 |
| 最近记录: |