Một cách tiếp cận là tạo một tệp XML như thế này drawable, có tên là anything.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/bgalt" />
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/bgalt" />
<item android:drawable="@drawable/bgnorm" />
</selector>
bgaltvà bgnormlà hình ảnh PNG có thể vẽ được.
Nếu bạn tạo các nút theo chương trình trong hoạt động của mình, bạn có thể đặt nền bằng:
final Button b = new Button (MyClass.this);
b.setBackgroundDrawable(getResources().getDrawable(R.drawable.whatever));
Nếu bạn đặt kiểu nút của mình bằng XML, bạn sẽ làm như sau:
<Button
android:id="@+id/mybutton"
android:background="@drawable/watever" />
Và cuối cùng là một liên kết đến một hướng dẫn . Hi vọng điêu nay co ich.