Android 以编程方式更改 drawableRight
Android programmatically change drawableRight
如何以编程方式更改 drawableRight 图像?
这是我的带有 drawableRight 的按钮,已经设置了 drawableRight 图像 -
<Button
android:id="@+id/button"
android:layout_width="120dp"
android:layout_height="50dp"
android:layout_marginStart="11dp"
android:backgroundTint="#496a4a"
android:drawableRight="@drawable/ic_add_white_24px"
android:textColor="@android:color/white"
android:text="Shop"
android:layout_alignBaseline="@+id/button"
android:layout_alignBottom="@+id/button3"
android:layout_toEndOf="@+id/button2" />
这里我不会更改 drawableRight 图像 -
public void onClick(View v){
if(v.getId()==R.id.button){
//Log.d(TAG,"button");
// Need to change the drawableRight image !
}
}
button.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.drawableRight, 0);
如何以编程方式更改 drawableRight 图像?
这是我的带有 drawableRight 的按钮,已经设置了 drawableRight 图像 -
<Button
android:id="@+id/button"
android:layout_width="120dp"
android:layout_height="50dp"
android:layout_marginStart="11dp"
android:backgroundTint="#496a4a"
android:drawableRight="@drawable/ic_add_white_24px"
android:textColor="@android:color/white"
android:text="Shop"
android:layout_alignBaseline="@+id/button"
android:layout_alignBottom="@+id/button3"
android:layout_toEndOf="@+id/button2" />
这里我不会更改 drawableRight 图像 -
public void onClick(View v){
if(v.getId()==R.id.button){
//Log.d(TAG,"button");
// Need to change the drawableRight image !
}
}
button.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.drawableRight, 0);