0

我想在运行时将按钮的文本更改为图像,然后在某些用户交互中返回(而不是我想要文本返回的图像)。我怎样才能做到这一点?谁能给我一个例子?

据我了解,我无法使用图像按钮,因为我无法在其上添加文本。我试着用

setCompoundDrawables

但这对我不起作用(按钮上没有可见的变化)。这是我的代码:

 Button button = (Button) findViewById(R.id.button1);

 Drawable myDrawable = this.getResources().getDrawable(R.drawable.ic_launcher);
 myDrawable.setBounds(0, 0, 0, 0);

 button.setCompoundDrawables(myDrawable, null, null, null);

请帮忙

4

1 回答 1

1

我认为这是问题所在

myDrawable.setBounds(0, 0, 0, 0);

既然你已经放弃0left, top, right, bottom,就没有明显的变化。尝试为and提供一些值,例如10or ,您将能够看到变化。15rightbottom

于 2013-04-05T10:19:52.943 回答