我尝试将Android的内置图标(android.R.drawable.bla)放入一个ImageButton中,并想要改变图标的颜色(而不是背景),但结果并不如我所愿。
这是我尝试过的方法:
我的布局中的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" />
我在Activity中尝试的内容:
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的颜色,但它似乎行不通。
我是否在走正确的方向?还是有其他机会(我不是指在Photoshop中着色并将它们放入drawable文件夹中)?