Java 将背景图像添加到背景xml布局
我正在使用drawable中的xml文件使我的应用程序中的按钮“漂亮” ^像那样 它工作得很好,但是我想在按钮上加一个勾号或叉号(以标记完成与否)-我不太确定这是否可行 以下是我的按钮xml:Java 将背景图像添加到背景xml布局,java,android,drawable,Java,Android,Drawable,我正在使用drawable中的xml文件使我的应用程序中的按钮“漂亮” ^像那样 它工作得很好,但是我想在按钮上加一个勾号或叉号(以标记完成与否)-我不太确定这是否可行 以下是我的按钮xml: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pres
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="#449def" />
<stroke
android:width="1dp"
android:color="#2f6699" />
<corners
android:radius="3dp" />
<padding
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#449def"
android:endColor="#2f6699"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#2f6699" />
<corners
android:radius="4dp" />
<padding
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp" />
</shape>
</item>
</selector>
我正在将按钮上的背景元素设置为使用上面的按钮,如@drawable/bluebuttons
如果您正在使用button,那么您可以在XML文件中使用button的属性,我们将非常感谢您的帮助
android:drawableRight=“@drawable/ANY\u drawable\u IMAGE”
我的情况是这样的:
<Button android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
...
...
android:drawableRight="@drawable/ic_tick" />
// PUT ZERO FOR NO DRAWABLE
textView1.setCompoundDrawablesWithIntrinsicBounds(LEFT_DRAWABLE, TOP_DRAWABLE,RIGHT_DRAWABLE, BOTTOM_DRAWABLE);
希望这将对您有所帮助。如果您有兴趣从
活动中动态设置按钮上的图像,那么您可以使用:
Drawable iconTick= getApplicationContext().getResources().getDrawable(R.drawable.icon_tick);
mBtnTaks1.setCompoundDrawablesWithIntrinsicBounds(iconTick, null, null, null); // left,top,right,bottom
谢谢。先生,您是一位传奇人物。非常感谢-如果您想从活动
动态处理此问题,当我发布解决方案时,我会接受它。