如何更改编程一个按钮的图标?图标、按钮、如何更改

2023-09-04 08:29:13 作者:稳妥熟男

我已经有按钮:

 <按钮
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =FILL_PARENT
机器人:drawableLeft =@可绘制/空
机器人:ID =@ + ID / buttonMyText
机器人:文本=会将myText
机器人:TEXTSIZE =20像素
机器人:重力=左>
< /按钮>
 

我有空图标显示的按钮,程序启动时。

我想要做的就是从我的基于用户输入code(低,中,高)自动更改按钮的图标

我想:

 按钮myButton的= BLA BLA ... ...喇嘛...
 

不过,我无法弄清楚

  myButton的。(是什么?)
 
不真实体验 这么轻的电脑,怎么才卖5000块钱

解决方案

如果您检查文档,你会看到code相当于每个XML属性。

下面参见:http://developer.android.com/reference/android/widget/Button.html

搜索 drawableLeft 显示:

 机器人:drawableLeft:
setCompoundDrawablesWithIntrinsicBounds(可绘制,绘制对象,可绘制,绘制对象)
 

I already have the button:

<Button 
android:layout_height="wrap_content" 
android:layout_width="fill_parent"
android:drawableLeft="@drawable/empty"
android:id="@+id/buttonMyText" 
android:text="  myText" 
android:textSize="20px" 
android:gravity="left">
</Button>

I have the "empty" icon show on the button when the program starts.

What I want to do is change the button's icon automatically from my code (low, medium and high) based on user inputs

I tried:

Button myButton = bla... bla... bla...

But I cant figure out

myButton.(what?)

解决方案

If you check the docs, you'll see the code equivalent for each XML attribute.

See here: http://developer.android.com/reference/android/widget/Button.html

Searching for drawableLeft shows:

android:drawableLeft:
setCompoundDrawablesWithIntrinsicBounds(Drawable,Drawable,Drawable,Drawable)