Android的按键采用与不同的图像文本启用和pressed [英] Android Button with Text with different images for Enabled and Pressed
问题描述
我想创建具有状态按钮文本
和图片
上通过以下$ C顶部$ C:
I am trying to create a stateful Button having Text
and an Image
on the top via the following code:
<Button
android:id="@+id/btnMultiplayer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="@drawable/multiplayer"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="Multiplayer"/>
要得到这样的:
不过,我找不到改变绘在上面当图像pssed $ P $的方式。
However, I couldn't find the way to change the drawable on the top when the image is pressed.
我试图设置的android:drawableTop
到 @绘制/ multiplayer_stateful
,其中 @drawable / multiplayer_stateful
是:
I tried to set android:drawableTop
to @drawable/multiplayer_stateful
where @drawable/multiplayer_stateful
is :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawableTop="@drawable/multiplayer" android:state_enabled="true" android:state_window_focused="false"/>
<item android:drawableTop="@drawable/multiplayer_pressed" android:state_pressed="true"/>
</selector>
但是,这并不正常工作。 (请注意,@绘制/多人和@绘制/ multiplayer_ pressed是PNG文件)
but this doesn't work. (Note that @drawable/multiplayer and @drawable/multiplayer_pressed are png files)
有什么建议?
推荐答案
您必须使用的android:抖动=真正的
试试这个。
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true" >
<item android:drawableTop="@drawable/multiplayer" android:state_enabled="true" android:state_window_focused="false"/>
<item android:drawableTop="@drawable/multiplayer_pressed" android:state_pressed="true"/>
</selector>
从Android电子文档:
From Android Docs:
启用或禁用抖动位图如果位图不
具有相同的像素结构的屏幕(例如:一个ARGB
8888位与RGB 565屏幕)。
Enables or disables dithering of the bitmap if the bitmap does not have the same pixel configuration as the screen (for instance: a ARGB 8888 bitmap with an RGB 565 screen).
必须是一个布尔值,无论是真或假。
Must be a boolean value, either "true" or "false".
这也可能是一个资源的引用(形式
@ [包:]类型:名称)或主题属性(形式
[包:] [类型:]名。包含此类型的值)
This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.
抖动影响颜色是更高precision比设备如何降采样。无抖动一般更快,但高于precision颜色只是截断下来(例如8888 - > 565)。抖动尝试分配固有的误差在此过程中,以减少视觉伪影
Dithering affects how colors that are higher precision than the device are down-sampled. No dithering is generally faster, but higher precision colors are just truncated down (e.g. 8888 -> 565). Dithering tries to distribute the error inherent in this process, to reduce the visual artifacts.
我希望它能帮助!
这篇关于Android的按键采用与不同的图像文本启用和pressed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!