我为一个按钮制作了一个边框,当按钮被点击时,这个边框应该是启用的。
<Button
android:id="@+id/imageView_red"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:src="@drawable/border" />
我的问题是如何启用/禁用此可绘制?java提供了解决这个问题的方案吗?
我试着看了这篇文章,但它似乎没有回答这个问题
发布于 2018-06-19 05:02:24
你所需要做的就是把选择器放在按钮里,如下所示
<Button
android:id="@+id/button1"
android:background="@drawable/selector_xml_name"
android:layout_width="200dp"
android:layout_height="126dp"
android:text="Hello" />
像这样的抽屉
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<stroke android:width="10dp"/>
</shape>
</item>
<item android:state_pressed="false">
<shape>
<stroke android:width="0dp"/>
</shape>
</item>
https://stackoverflow.com/questions/50917163
复制相似问题