如何显示上的ImageButton的文字? [英] How to show the text on a ImageButton?

查看:201
本文介绍了如何显示上的ImageButton的文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ImageButton的,我想展示一个文本,并在其上​​一个图像。但是,当我尝试

I have a ImageButton and I want show a text and a image on it. But when I try

<ImageButton 
android:text="OK" 
android:id="@+id/buttonok" 
android:src="@drawable/buttonok"
android:layout_width="match_parent" 
android:layout_height="wrap_content"/>

我坐上模拟器的按钮有图像,但没有文字。我怎样才能显示文本,请帮帮我!

I get on Emulator the button have image but without the text. How can i show the text, please help me !

推荐答案

正如你不能使用安卓文本我建议你使用一个普通按钮,并使用一个的化合物,可绘制。例如:

As you can't use android:text I recommend you to use a normal button and use one of the compound drawables. For instance:

<Button 
    android:id="@+id/buttonok" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/buttonok"
    android:text="OK"/>

您可以把绘制,无论你想使用: drawableTop drawableBottom drawableLeft drawableRight

You can put the drawable wherever you want by using: drawableTop, drawableBottom, drawableLeft or drawableRight.

更新

有关按钮这也适用pretty的罚款。把安卓!背景

For a button this too works pretty fine. Putting android:background is fine!

<Button
    android:id="@+id/fragment_left_menu_login"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/button_bg"
    android:text="@string/login_string" />

我只是有这个问题,并正在完美。

I just had this issue and is working perfectly.

这篇关于如何显示上的ImageButton的文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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