代码之家  ›  专栏  ›  技术社区  ›  Yin Zhu

更改程序中按钮上的文本

  •  3
  • Yin Zhu  · 技术社区  · 14 年前

    “我的按钮”上的文本是在资源文件中设置的。例如。

                <Button android:id="@+id/up_button" android:layout_width="fill_parent"
                    android:layout_height="wrap_content" android:text="@string/up_label" />
    

    上面的代码定义了一个带有文本的按钮 @string/up_label

    谢谢。

    3 回复  |  直到 14 年前
        1
  •  8
  •   Nithin Michael    11 年前
    Button myButton = (Button) findViewById(R.id.up_button);
    myButton.setText("my text");
    

    也许这会有帮助。

        2
  •  5
  •   alex.zherdev    14 年前

    或者,如果你在参考资料中有新的文本(我认为你有),你有

    Button myButton = (Button) findViewById(R.id.up_button);
    myButton.setText(R.string.down_label);
    

    哪里 down_label

        3
  •  1
  •   Mathias    11 年前

    Button Button=(按钮)findViewById(R.id.up_按钮);

    例如:

    button.setText("This is how to change text at runtime");