开发者

android toast a Chinese message to user

开发者 https://www.devze.com 2023-01-31 17:56 出处:网络
Basically I need to toast a message written in Chinese t开发者_JAVA百科o user. However I don\'t know how to achieve such thing.

Basically I need to toast a message written in Chinese t开发者_JAVA百科o user. However I don't know how to achieve such thing. Any solution that can help me?


I'm not an Android programmer, but doesn't this work?

Context context = getApplicationContext();
CharSequence text = "中国的网页";
int duration = Toast.LENGTH_SHORT;

Toast toast = Toast.makeText(context, text, duration);
toast.show();

Code ripped from here.

(Apologies if that means anything offensive. I simply ripped some random characters from here).


I found my own answer. It's so simple I didn't think of that in the first place. And it always works. Under res/values/string.xml of Android project, I edit:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="sample">中国的网页</string>
</resources>

And the I retrieve the string name "sample" out of project's resource using:

this.getString(R.string.sample);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号