如何将图像按钮的背景设置为圆形,以便在按下它时背景显示圆形背景而不是方形背景?
第一轮(在操作栏中):
方形一(普通 ImageButton):
最佳答案
我想通了!
我正在使用名为 button_background.xml
的选择器
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/circle_background" />
</selector>
还有一个圆形背景可绘制对象:circle_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#1f000000" />
</shape>
现在只需将它设置为 ImageView 的背景:
<ImageButton
android:background="@drawable/button_background"
android:id="@+id/edit"
android:layout_width="wrap_content"
android:layout_height="72dp"
android:layout_alignParentRight="true"
android:contentDescription="@string/popup_edit"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:src="?attr/more" />
Et voilá :)
关于Android:关于ImageButton的循环反馈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29677571/