2016-08-12 1 views
1

ボタンの左に描画可能なアイコンの色を変更する方法を理解しようとしています。私はandroid:tintが、アイコンの色が変化していない試してみましたボタンの左に描画可能なアイコンの色を変更するにはどうすればよいですか?

<Button 
     android:layout_width="wrap_content" 
     android:layout_height="20dp" 
     android:layout_toRightOf="@+id/student_images" 
     android:drawableLeft="@mipmap/ic_email_black_18dp" 
     android:text=" [email protected] " 
     android:layout_below="@+id/email" 
     android:background="#00000000" 
     android:layout_marginBottom="20dp" 
     android:fontFamily="sans-serif" 
     android:textColor="@color/gray_text_color" 
     /> 

以下は、私が使用していますXMLコードです。私はここで立ち往生している。

答えて

3

あなたは、プログラムで以下のような色合いを設定することができます。

int tintColor = ContextCompat.getColor(context, android.R.color.darker_gray); 

Button button = (Button) findViewById(R.id.button); 

Drawable drawable = ContextCompat.getDrawable(context, R.mipmap.ic_email_black_18dp); 
drawable = DrawableCompat.wrap(drawable); 
DrawableCompat.setTint(drawable.mutate(), tintColor); 

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

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

それともsnodnipperにより、ライブラリSupport Drawable Tintsを使用することができます。
このライブラリを使用すると、ボタンのdrawableLeftの色合いを設定できます。
https://github.com/snodnipper/android-appcompat-issue198613

+0

感謝を使う設定するしかし色合いはDrawableの左側で作業しませんが、はい、それは描画可能でうまく動作。 drawableLeftの色を変更する方法 –

+0

私の答えを更新しました。上記のコードはdrawableLeftの色を変更します。最初の行を色合いの色に変更し、上記のコードを使用してください。 – nshmura

1

アイコンの色は、ご返信用

android:drawableTint="@color/colorPrimary" 
+0

良い方法ですが、悲しいかな、SDK 23+でのみ利用可能です。 – CzarMatt

関連する問題