프로그래밍 방식으로 버튼의 drawableLeft/drawableRight 색상을 변경하는 방법을 알아 내려고하고 있습니다. 어떤 작품 아래에 언급 한 바와 같이 나는> 내 XML로 그릴 수 색조를 사용하고 23프로그래밍 방식으로 안드로이드에서 프로그래밍 방식으로 API 레벨 23 아래의 드로잉 색조를 변경하는 방법
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="VIEW ALL"
android:layout_centerInParent="true"
android:background="#00000000"
android:drawableLeft="@mipmap/ic_menu_black_36dp"
android:layout_centerVertical="true"
android:id="@+id/view_all"
android:textColor="@color/bottom_color"
android:drawableTint="@color/bottom_color"
/>
Button prev = (Button) findViewById(R.id.prev);
Drawable[] drawables =prev.getCompoundDrawables();
drawables[0].setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY);
prev.setCompoundDrawables(drawables[0],null,null,null);
솔루션 색상 < API 레벨을 변경할 수 API 레벨 23가 아니라 : 그래서 당신은 PorterDuff.Mode.MULTIPLY
를 사용하는
Drawable[] drawablesprev =prev.getCompoundDrawables();
//for drawableleft drawable array index 0
drawablesprev[0].setColorFilter(getResources().getColor(R.color.assessment_bottom), PorterDuff.Mode.SRC_ATOP);
//for drawableright drawable array index 2
drawablesprev[2].setColorFilter(getResources().getColor(R.color.assessment_bottom), PorterDuff.Mode.SRC_ATOP);
//for drawabletop drawable array index 1
drawablesprev[1].setColorFilter(getResources().getColor(R.color.assessment_bottom), PorterDuff.Mode.SRC_ATOP);
'android.support.v4.graphics.drawable.DrawableCompat'와'setTint (Drawable 드로어 블, int tint)'메소드 – pskink
을 사용하면 동일한 샘플 코드를 제공 할 수 있습니다. 나는 여기에 붙어있는 찐다 –
무엇에 갇혔습니까? 당신의 코드는 무엇입니까? – pskink