安卓的ImageButton有残疾的用户界面的感觉 [英] Android ImageButton with disabled UI feel
问题描述
我有一个ImageButton的是禁用(不点击,或者设置为禁用)。我想举一个UI觉得它是禁用的,而无需使用任何其它图像的用户。
I have an ImageButton which is disabled (non clickable or set as disabled). I want to give an UI feel to the user that it is disabled without using any other image.
有没有办法做到这一点?
Is there any way to do this?
推荐答案
不同于普通的按钮
,一个的ImageButton
或按钮
,有一个形象的背景不呈灰色禁用时。实际上,你必须使用另一幅图像或处理它在某种程度上,它显示为灰色。
Unlike a regular Button
, an ImageButton
or a Button
that has an image background is not grayed when disabled. You actually have to use another image or to process it in a way it appears grayed.
如果使用另一种形象是好的,您可以使用&LT做到这一点C $ C>但这amongs同一个):
Should using another image be ok, you can do this by using a <selector>
(here associated to a regular Button
but this amongs to the same):
-
/drawable/my_selector.xml
:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false"
android:drawable="@drawable/button_gray" /> ***button_gray is a Drawable image***
<item android:state_pressed="true"
android:drawable="@drawable/button_gray" />
<item android:drawable="@drawable/button_red" /> ***button_red is a Drawable image***
</selector>
下面,button_red用所有的时间,但是当按钮被禁用或推。
Here, button_red is used all the time but when the button is disabled or being pushed.
-
您
layout.xml
:
<Button android:id="@+id/myButton"
android:background="@drawable/my_selector" ***this is a reference to the selector above ***
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
和应该使用其他的图像是一个问题,其他的答案,如@ Tronman的或@ southerton我们给你的方法来处理它在某种程度上,它显示为灰色。
And should using another image be a problem, other answers such as @Tronman's or @southerton's give you ways to process it in a way it appears grayed.
这篇关于安卓的ImageButton有残疾的用户界面的感觉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!