Android 以编程方式删除按钮的左侧图像,但不删除右侧图像?
您好,我有两个左右可画的图像按钮,我只想删除左侧图像,并想保留右侧图像我的按钮xml代码如下Android 以编程方式删除按钮的左侧图像,但不删除右侧图像?,android,android-layout,android-studio,android-fragments,Android,Android Layout,Android Studio,Android Fragments,您好,我有两个左右可画的图像按钮,我只想删除左侧图像,并想保留右侧图像我的按钮xml代码如下 <Button android:id="@+id/fragment_add_to_cart_btn_proceed_to_checkout" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/colorRed"
<Button
android:id="@+id/fragment_add_to_cart_btn_proceed_to_checkout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorRed"
android:drawableEnd="@drawable/ic_action_next"
android:drawablePadding="5dp"
android:drawableStart="@drawable/ic_rounded_cart"
android:gravity="left|center_vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/proceed_to_checkout"
android:textColor="@color/colorWhite" />
我已经应用了下面的一些代码,但它不起作用
button.setCompoundDrawables(null,null,null,null)代码>
如果您有任何解决方案,请回复?
谢谢。试试看
button.setCompoundDrawablesWithIntrinsicBounds(0, 0, <your_left_drawable>, 0);
button.setCompoundDrawableSwithinInstincBounds(0,0,0);
希望它能帮到你。试试看
button.setCompoundDrawablesWithIntrinsicBounds(0, 0, <your_left_drawable>, 0);
button.setCompoundDrawableSwithinInstincBounds(0,0,0);
希望它能帮助您。您应该使用按钮。setCompoundDrawables(null,null,R.drawable.ic\u action\u next,null)
您应该使用按钮。setCompoundDrawables(null,null,R.drawable.ic\u action\u next,null)代码>尝试:
button.setCompoundDrawablesWithIntrinsicBounds(0, 0, <The right drawable>, 0);
尝试:
在onCreate
中执行此操作。提供图像
资源,您需要为其显示,否则将提供0
在onCreate
中执行此操作。提供图像
资源,您需要为其显示,否则将提供0
只需删除这一行:android:drawableStart=“@drawable/ic\u rounded\u cart”
我想以编程方式执行此操作。然后使用按钮。setCompoundDrawablesWithIntrinsicBounds(null,null,您的\u right\u drawable,null)代码>参考:只需删除这一行:android:drawableStart=“@drawable/ic\u rounded\u cart”
我想以编程方式执行此操作。然后使用按钮。setcompounddrawableswitthinstincbounds(null,null,您的\u right\u drawable,null)代码>参考:
button.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_rounded_cart, 0); // if you want to remove the left drawable
int imgResource = R.drawable.common_google_signin_btn_icon_dark;
fragment_add_to_cart_btn_proceed_to_checkout = (Button) findViewById(R.id.fragment_add_to_cart_btn_proceed_to_checkout);
fragment_add_to_cart_btn_proceed_to_checkout.setCompoundDrawablesWithIntrinsicBounds(0, 0, imgResource, 0);