Raj*_*ddy 17
1.为按钮状态准备3张图像,并将其放入resource/drawable文件夹中.
2.在res/drawable/文件夹中创建一个新的XML文件,无论你想要什么名字,在这种情况下,我们只需给出一个名称my_button.xml.该文件定义了哪个按钮状态属于哪个图像.
现在,您可以通过此Id参考此按钮:@ drawable/my_button.
文件:res/drawable/my_button.xml
使用这样的按钮图像以创建XML文件my_button.xml的drawable文件夹
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_pressed_yellow"
android:state_pressed="true" />
<item android:drawable="@drawable/button_focused_orange"
android:state_focused="true" />
<item android:drawable="@drawable/button_normal_green" />
</selector>
Run Code Online (Sandbox Code Playgroud)
添加一个普通按钮,并将背景图像附加到"my_button"上方
android:background:@drawable/my_button
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10666 次 |
| 最近记录: |