如何更改编程一个按钮的图标? [英] How to Change a Button's Icon Programmatically?

查看:116
本文介绍了如何更改编程一个按钮的图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有按钮:

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

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

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

我想:

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

不过,我无法弄清楚

  myButton的。(是什么?)
 

解决方案

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

下面参见:<一href="http://developer.android.com/reference/android/widget/Button.html">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)

这篇关于如何更改编程一个按钮的图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆