<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="1px" android:color="#696969"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
此代码用于动态创建按钮,问题是我想设置背景颜色并设置背景可绘制对象。
Button btnTag = new Button(alltable.this);
btnTag.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
try {
btnTag.setWidth(130);
btnTag.setBackground(getResources().getDrawable(R.color.blue));
} catch (Exception e){
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
这是一类,我想设置btn的背景色,然后使用我的drawable。