如何在java(不是XML)中创建形状(矩形),然后将其设置为按钮的背景。
我需要将形状设置为按钮的背景。
这是形状 frame.xml :
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<corners android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"/>
<stroke android:width="4dp" android:color="#000000" />
<padding android:left="1dp" android:top="1dp" android:right="1dp"
android:bottom="1dp" />
</shape>
然后在 MainActivity.java :
btnDown.setBackground(getResource().getDrawable(R.drawable.frame);
当我开始节目时,我正是我需要的:
我无法发布屏幕(小口碑)
但是在我隐藏应用程序或主页按钮,然后回到应用程序后我有一些文物:背景上的形状占据按钮空间的一半
我尝试在xml,setBackgroundDrawable()
,setBackgroundResourse()
中设置背景,但按钮显示不正确。