更改程序中按钮的文本

Yin*_*Zhu 4 android button

我的按钮上的文本在资源文件中设置.例如

            <Button android:id="@+id/up_button" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:text="@string/up_label" />
Run Code Online (Sandbox Code Playgroud)

上面的代码定义了一个带文本的按钮@string/up_label.如何在应用程序运行期间更改程序中的此文本.

谢谢.

小智 8

Button myButton = (Button) findViewById(R.id.up_button);
myButton.setText("my text");
Run Code Online (Sandbox Code Playgroud)

也许这会有所帮助.


ale*_*dev 5

或者,如果您在资源中有新文本(我认为是这样),则可以

Button myButton = (Button) findViewById(R.id.up_button);
myButton.setText(R.string.down_label);
Run Code Online (Sandbox Code Playgroud)

down_label字符串的ID 在哪里。