你需要使用Android的Button控件,然后通过代码来设置它的文本。
例如,你可以在你的XML布局文件中添加一个Button控件,并为它设置一个id:
```xml
android:id="@+id/myButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="点击我" /> ``` 然后在你的Java代码中,你可以使用findViewById()方法获取到这个Button控件,并通过调用setText()方法来设置它的文本: ```java Button myButton = findViewById(R.id.myButton); myButton.setText("新的文本"); ``` 这样就可以通过代码来改变按钮的文字了。
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="点击我" />
```
然后在你的Java代码中,你可以使用findViewById()方法获取到这个Button控件,并通过调用setText()方法来设置它的文本:
```java
Button myButton = findViewById(R.id.myButton);
myButton.setText("新的文本");
这样就可以通过代码来改变按钮的文字了。
查看详情