Android:关于ImageButton的循环反馈

标签 android layout

如何将图像按钮的背景设置为圆形,以便在按下它时背景显示圆形背景而不是方形背景?

第一轮(在操作栏中):

Round

方形一(普通 ImageButton):

Square

最佳答案

我想通了!

enter image description here

我正在使用名为 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/

相关文章:

html - 使 block 适合其内容,但保留其 block 能力

java - 将空字符串解析为int

ruby-on-rails - 在 Rails 3 : How do I render with layout in respond_with using a custom format?

android - 将视频转码以降低比特率并流式传输

java - 调用自写类时出现NullPointerException

java - 根据组件大小自动化 JFrame 边界

javascript - 您如何测量文本在 Javascript 中占用的空间?

Java Swing Card Layout 更改显示的面板?

android - 一个意料之外的问题发生了。请稍后再试。 (738369013) 提交到 PlayStore 时

android - RecyclerView Children 计数小于 children 数量