-2

I am using android:drawableLeft="@mipmap/share_icon" in android button to show icon. I want to change color and size of icon. Below is my code

<Button
        style="@android:style/Widget.Holo.Light.Button.Small"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:layout_marginBottom="15dp"
        android:background="#66ccff"
        android:clickable="true"
        android:drawableLeft="@mipmap/share_icon"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:text="Send An Invite"
        android:textColor="@color/white_color"
        android:textSize="18sp"
        android:textStyle="normal"
        android:tint="@color/white_color"
        />
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
GAURAV
  • 647
  • 6
  • 18

2 Answers2

0

Open the xml file of share_icon in mipmap and change colour and resize from there.

Raj
  • 2,997
  • 2
  • 12
  • 30
0

Note: The mipmap folders are for placing your app/launcher icons (which are shown on the homescreen) in only. Any other drawable assets you use should be placed in the relevant drawable folders as before.

Follow these steps:

Step #1

Wrap your resource in a drawable that defines your desired size similar to:

 <?xml version="1.0" encoding="utf-8"?>
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

      <item
         android:drawable="@drawable/{your icon}"
         android:width="@dimen/icon_size"
         android:height="@dimen/icon_size" />

 </layer-list >

Step #2

Remove the android:drawableLeft tag from your Button

Step #3

Add this code to your Activity / Fragment

int tintColor = ContextCompat.getColor(context,
android.R.color.{your button color});

Button button = (Button) findViewById(R.id.{your button id});

Drawable drawable = ContextCompat.getDrawable(context, R.drawable.{drawable that you made earlier});

drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable.mutate(), tintColor);

drawable.setBounds( 0, 0, drawable.getIntrinsicWidth(), 
drawable.getIntrinsicHeight());

button.setCompoundDrawables(drawable, null, null, null);

Keep in mind: (Assuming you didn't know)

  • For the above code to work, you should add an id to your Button.
  • If you're using an Activity, use getApplicationContext() and if you're using a Fragment, use getContext()
  • Add the desired color to the colors.xml file