android string里面怎么使用
答案:2 悬赏:10
解决时间 2021-03-02 20:30
- 提问者网友:太高姿态
- 2021-03-01 21:24
android string里面怎么使用
最佳答案
- 二级知识专家网友:十鸦
- 2021-03-01 22:30
首先 你在strings.xml文件里写上你要显示的内容:
如:
Hello World, MainActivity!
android系统后自动在R.java中生成一个引用
public static final class string
{
public static final int hello=0x7f040000;
}
这个不用程序员实现。
然后在你代码中需要使用时只需要调用R.string.hello即可.
textView.setText(R.string.hello)。
如:
Hello World, MainActivity!
android系统后自动在R.java中生成一个引用
public static final class string
{
public static final int hello=0x7f040000;
}
这个不用程序员实现。
然后在你代码中需要使用时只需要调用R.string.hello即可.
textView.setText(R.string.hello)。
全部回答
- 1楼网友:你可爱的野爹
- 2021-03-01 23:37
在布局文件里面用的话,例如TextView android:text="@string/test"
这里的test就是string文件里面的name<string name="test">测试显示</string>
在代码里面引用textview.setText(getResources().getString(R.string.test));
这里的test就是string文件里面的name<string name="test">测试显示</string>
在代码里面引用textview.setText(getResources().getString(R.string.test));
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯