[英]Have a Button with 3 different background images. Android Studio, XML, Java
can somedy help me, and tell me whats wrong in this code?有人可以帮我,告诉我这段代码有什么问题吗? I have 3 different background pictures of my shack, (green, grey, normal) and in the Java Code below i check which state is active
我有 3 张不同的小屋背景图片(绿色、灰色、正常),在下面的 Java 代码中,我检查哪个状态是活动的
You can directly set the image of button in different conditions like this:-您可以在不同条件下直接设置按钮的图像,如下所示:-
((ImageButton)shackButton).setImageResource(R.drawable.<imageid>);
You can do it without creating any other resource file.您可以在不创建任何其他资源文件的情况下执行此操作。
change your xml to this将您的 xml 更改为此
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/shack1000green" android:state_focused="true" android:state_pressed="true"/>
<item android:drawable="@drawable/shack1000grey" android:state_focused="false" android:state_pressed="true"/>
<item android:drawable="@drawable/shack1000" android:state_focused="false" android:state_pressed="false"/>
</selector>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.