按钮上的 Android ADT 文字

标签 android xml button

我创建了一个按钮:

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textBox"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="84dp"
    android:text="@string/Button" />

但最后一行应使按钮上的文本为:“按钮”。 但是我得到的文本是“@string”。

另一个问题: 按钮中的文本右对齐。如何使它居中?

最佳答案

这是因为在 strings.xml 中没有任何名为 Button 的字符串。 这样做

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textBox"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="84dp"
    android:text="Button" />

或者在你的 values/strings.xml 中创建一个新的字符串作为

 <string name="Button">Button</string>

并在你的xml中使用它

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textBox"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="84dp"
    android:text="@string/Button" />

关于按钮上的 Android ADT 文字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19333117/

相关文章:

android - canvas.drawCircle 不起作用 - 而 drawLine 起作用 - 可能是由使用 Sherlock 引起的?

在包含任何字符的设置中序列化 List<string> 的 C# 方法 (Regex/xml)

javascript - window.showModalDialog 和回发按钮

c# - 按钮 PlayerPrefs

android - 没有这样的属性 : variantConfiguration for class:

android - Android Studio 中抽屉导航菜单中第一项的上边距

xml - Go - 如何使用 slice 将 XML 解码到容器结构中

xml - 删除 XSLT 中的前导 0

html - 无法对齐多个按钮上的文本/链接 - 菜鸟级别

Android 警报对话框复选框文本