我为按钮制作了一个边框,单击该按钮时应启用该边框。
<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 是否为此提供了解决方案?
我试着看这篇文章,但它似乎没有回答这个问题
最佳答案
你需要做的就是像这样把选择器放在按钮上
<Button
android:id="@+id/button1"
android:background="@drawable/selector_xml_name"
android:layout_width="200dp"
android:layout_height="126dp"
android:text="Hello" />
像这样的drawable
<?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>
关于java - 如何在 android 中启用/禁用按钮对象的可绘制对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50917163/