带有文字的Android Imagebutton

时间:2015-04-22 08:36:42

标签: android

我正在制作一个Android应用程序,它有一些按钮,比如我附加的图片,这些按钮是带有GradientDrawable(button.setBackgroundDrawable (gd);)的ImageButton到图片框架,button.setImageBitmap (bp);这是要开始的图像申请费最后得到ab utton.setBackgroundColor (Color.TRANSPARENT);为背景颜色。

链接图片:

enter image description here

我的问题是,有没有办法让我按照与附加图片相同的方式保持按钮,但按钮上有文字?是ImageButton没有添加文本的选项,应该使用简单的Button但不支持此按钮来放置这四个特征并保持在照片中。最后,我尝试实现的是与我附上的照片最接近的按钮,但中间有一个文本。

代码我用来放置按钮的图像和设计。

final ImageButton button = new ImageButton(this);
button.setBackgroundColor(Color.TRANSPARENT);
button.setImageBitmap(bp);

button.setAdjustViewBounds(true);
button.setId(contador);
button.setBackgroundDrawable(gd);

2 个答案:

答案 0 :(得分:0)

ImageButton不支持文本添加,而是可以使用Button并将其背景设置为图像和文本。

看一下这个主题:Set the text in ImageButton

答案 1 :(得分:0)

最后,我将一个带有setCompoundDrawablesWithIntrinsicBounds属性的TextView和一个drawable放在顶部,并将文本放在bot上