Java 给我的纽扣上色的最好方法是什么?
我目前正在开发一个android应用程序,我使用透明的png作为用户界面的按钮 按钮看起来有点像这样: 当用户按下按钮时,我想自动将图像中的不透明像素着色为较暗的颜色 目前,我使用了一个xml选择器,每个状态都有不同的可绘制项。这显然不能很好地扩展,因为我需要在photoshop中制作每个图像的多个版本 有什么解决办法吗?我听说您可以在ImageView上使用setColorFilter方法来实现这一点,但是完整的解释将非常好Java 给我的纽扣上色的最好方法是什么?,java,android,Java,Android,我目前正在开发一个android应用程序,我使用透明的png作为用户界面的按钮 按钮看起来有点像这样: 当用户按下按钮时,我想自动将图像中的不透明像素着色为较暗的颜色 目前,我使用了一个xml选择器,每个状态都有不同的可绘制项。这显然不能很好地扩展,因为我需要在photoshop中制作每个图像的多个版本 有什么解决办法吗?我听说您可以在ImageView上使用setColorFilter方法来实现这一点,但是完整的解释将非常好 谢谢 将此图像设置为ImageButton的源,并使用xml状态列
谢谢 将此图像设置为ImageButton的源,并使用xml状态列表设置ImageButton的状态(backgriund),如下所示
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape
>
<gradient
android:startColor="@android:color/background_light"
android:endColor="@android:color/darker_gray"
android:angle="90"/>
<stroke
android:width="1dp"
android:color="#999999" />
<corners
android:radius="9dp"/>
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp"/>
</shape>
</item>
<item android:state_focused="true">
<shape>
<gradient
android:endColor="@android:color/transparent"
android:startColor="@android:color/transparent"
android:angle="270"/>
<stroke
android:width="1dp"
android:color="#989797" />
<corners
android:radius="9dp"/>
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp"/>
</shape>
</item>
<item>
<shape>
<gradient
android:endColor="@android:color/transparent"
android:startColor="@android:color/transparent"
android:angle="90"/>
<stroke
android:width="1dp"
android:color="#999999" />
<corners
android:radius="9dp"/>
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp"/>
</shape>
</item>
</selector>
我得说,这看起来很不错,但这不是我要找的,它用灰色填充背景,我希望图像中不透明的绿色像素变暗。@monoceres。。现在这真的很难。。。我认为在photoshop中创建图像是一种方法。。Donno如果还有其他方法..@monoceres。。看看这两个答案。。。和