【发布时间】:2013-01-05 18:01:39
【问题描述】:
我一直在寻找这个,但真的想不出任何干净的方法来做到这一点。
我正在开发一个带有一些按钮的应用程序,主要是这样定义的:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000000"
android:contentDescription="@null"
android:src="@drawable/btn1" />
有一个onTouchListener 可以用setAlpha(0.5f) 更改按钮的alpha,但它也会更改背景alpha,这不是我需要的。我想让它看起来更暗,而不是透明。
我已经看到了这个问题:Android Graphics: Changing the alpha of just an image (not the background),并且该解决方案确实有效,但是为我的应用程序中的每个按钮创建一个 FrameLayout 听起来并不好。
鉴于背景是纯色,我认为会有一个更简单的解决方案,例如颜色混合或类似的东西,但真的在任何地方都找不到。
解决方案
刚刚发现这个帖子:http://tech.chitgoks.com/2011/04/17/android-change-imagebutton-tint-to-simulate-button-pressed/
解决方法很简单:
button.setColorFilter(Color.argb(150,0,0,0));
【问题讨论】:
标签: android imagebutton alpha