【问题标题】:I can not see text on the Image button? [duplicate]我在图像按钮上看不到文字? [复制]
【发布时间】:2012-10-15 13:55:57
【问题描述】:

可能重复:
How to show the text on a ImageButton?

xml 有什么问题,我在按钮上看不到我的文字

    <ImageButton
    android1:id="@+id/btnShowLocation"
    android1:layout_width="wrap_content"
    android1:layout_height="wrap_content"
    android1:layout_alignParentBottom="true"
    android1:layout_centerHorizontal="true"
    android1:contentDescription="@string/empty"
    android1:layout_marginBottom="40dp"
    android1:src="@drawable/blue_button"
    android1:background="@null"
    android1:text = "@string/here_and_now"
    android1:textColor="@string/black_color"
    android1:gravity="center"
   />

【问题讨论】:

  • 你在使用 android1 吗?它的机器人:不是 android1
  • 好的,但是 android1 对我有用 schemas.android.com/apk/res/android" android1:layout_width="wrap_content" android1:layout_height="match_parent" android1:background="@color/white" android1 :gravity="top" xmlns:android="schemas.android.com/apk/res/android">

标签: android text


【解决方案1】:

您不能将android:text用于ImageButton。所以只需使用一个按钮并为其设置背景。

例如:

<Button 
   android1:id="@+id/btnShowLocation"
   android:layout_height="wrap_content"
   android:layout_width="wrap_content"
   android:layout_gravity="center"
   android:padding="10dp"
   android1:text = "@string/here_and_now"
   android:background="@drawable/blue_button"/>

【讨论】:

  • 为什么我们不能使用 android:text ?.. 我们可以!
  • 因为图片按钮默认没有属性文字。查看点击this
  • 那么不要给出这些属性中的任何一个。只需定义文本:“OK”。它会显示在中心。
  • 只需设置按钮的背景并给出文本。
  • so 而不是 drawble 使用背景
【解决方案2】:

我在 ImageButton 标签下找不到 android:text 属性。

您应该使用按钮并使用“背景”属性将图像放在按钮上。

<Button android:id="@+id/friendsListButton" android:gravity="center"
        android:layout_height="wrap_content" android:layout_width="wrap_content"
        android:text="@string/friendsListScreen" android:background="@drawable/blue_button"/>

如果您想要按钮上的图像,只需按上述定义即可。

【讨论】:

  • drawableTop, drawableLeft 给了我可怕的结果,因为如果我使用 drawableTop,文本会向下,如果我使用 drawableLeft,文本会向右......
  • 所以不要给任何 drawableTop 或任何东西。只需按照我的答案定义按钮即可。你想要按钮上的图像还是文本?
  • 我使用背景而不是可绘制的。并得到了所需的结果。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-31
  • 1970-01-01
  • 2015-01-11
  • 1970-01-01
相关资源
最近更新 更多