gpt4 book ai didi

android - 我如何找出当前分配给android :text property of a button view?的字符串资源

转载 作者:行者123 更新时间:2023-11-30 03:16:32 26 4
gpt4 key购买 nike

在我的 Activity 中,我试图根据按钮上显示的文本做出决定。我通过这样做让它工作:

if( startButton.getText() == "Stop" ) {
startButton.setText("Start");
} else {
startButton.setText("Stop");
}

但我想以一种独立于语言的方式来做,所以通过使用字符串的名称,因为它存在于 strings.xml 中,即“start_text”和“stop_text”。

最佳答案

您可以使用 getTag()setTag()例如

if (startButton.getTag(R.id.state).equals("play")) {
startButton.setText("Start");
startButton.setTag(R.id.state, "stop");
} else {
startButton.setText("Stop");
startButton.setTag(R.id.state, "play");
}

关于android - 我如何找出当前分配给android :text property of a button view?的字符串资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19988332/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com