user2043332
user2043332

Reputation: 395

How to change the color of intern Android drawables?

I've tried to put the intern icons of Android (anrdoid.R.drawable.bla) into an ImageButton and I wanted to change the color of Icon (not the Background!), but it doesn't work like I want to.

Here is what I've tried:

my ImageButton from the Layout:

<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" />

what I've tried in my 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);

No matter what Values I've tried for the LightingColorFilter it always gives the same result. The icon inside the Imagebutton gets dark. But thats not what I wnated. I just wanted to apply a color from my colors.xml, it somehow doesnt work out.

Is this even the right direction I'm going? Or is there another opertunity (And I don't mean coloring myself in Photoshop and putting them into the drawables folder)

Upvotes: 3

Views: 1997

Answers (1)

Marko Niciforovic
Marko Niciforovic

Reputation: 3601

this worked for me, for example it will paint in dark gray:

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

Upvotes: 7

Related Questions