如果我在名为test.xml的文件中有一个xml按钮,如下所示:
<Button
android:id="@+id/newgame"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New Game"
/>
是否可以将“新游戏”文字更改为其他内容?我必须多次这样做。 最大的问题是:我必须从java文件中做到这一点!这甚至可能吗?
答案 0 :(得分:5)
是
1)获取对Button的引用
2)使用setText方法为文本提供新值
Button button = (Button)findViewById(R.id.newgame);
button.setText("Something Else");
答案 1 :(得分:0)
在xml中,它将是静态的,使其成为动态,在java类中设置文本。 感谢