Android 更改程序中按钮上的文本
“我的按钮”上的文本在资源文件中设置。例如Android 更改程序中按钮上的文本,android,button,Android,Button,“我的按钮”上的文本在资源文件中设置。例如 <Button android:id="@+id/up_button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/up_label" /> 上面的代码定义了一个带有文本@string/up\u label的按钮。在应用程序运行期间,如何
<Button android:id="@+id/up_button" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/up_label" />
上面的代码定义了一个带有文本@string/up\u label
的按钮。在应用程序运行期间,如何在程序中更改此文本
谢谢
Button myButton = (Button) findViewById(R.id.up_button);
myButton.setText("my text");
也许这会有帮助。或者,如果参考资料中有新的文本(我想你有),你也有 其中
down\u label
是字符串的id。Button Button=(Button)findViewById(R.id.up\u Button)
例如:
button.setText("This is how to change text at runtime");
button.setText("This is how to change text at runtime");