2013-04-05 38 views
3

我试图把Android的实习生图标(anrdoid.R.drawable.bla)放到ImageButton 中,我想改变图标的​​颜色(不是背景!),但它不起作用,就像我想要。如何更改实习生Android可绘制的颜色?

这里是我试过:

从布局我的ImageButton:

<ImageButton 
    android:id="@+id/imageButton1" 
    android:layout_marginTop="100dp" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/background" 
    android:src="@android:drawable/ic_lock_silent_mode" /> 

什么我试着在我的活动:

Drawable myIcon = getResources().getDrawable(android.R.drawable.ic_lock_silent_mode); 
    ColorFilter filter = new LightingColorFilter(R.color.blue, R.color.blue); 
    myIcon.setColorFilter(filter); 

无论什么样的价值观我已经试过了LightingColorFilter,它总是给出相同的结果。 Imagebutton内的图标变暗。但那不是我所想的。我只是想从我的colors.xml中应用一种颜色,但它无法解决问题。

这就是我要去的正确方向吗?还是有另一种opertunity(我的意思不是着色自己在Photoshop和将它们放入了绘图资源文件夹)

回答

7

这个工作对我来说,例如,它会以暗灰色漆:

ImageButton imgBtn = (ImageButton) findViewById(R.id.imageButton11); // image button 
      imgBtn.setColorFilter(getResources().getColor(android.R.color.darker_gray), Mode.SRC_ATOP); 
+0

谢谢!完美的作品 – user2043332 2013-04-05 13:46:59

+0

没问题,很高兴我可以帮忙) – 2013-04-05 13:47:33

相关问题