使用区别的是:
getResources().getText(R.string.hello_world)
Run Code Online (Sandbox Code Playgroud)
和:
R.string.hello_world
Run Code Online (Sandbox Code Playgroud)
第二种方式,应该返回一个int对象.我刚尝试过:
Toast.makeText(getApplicationContext(), getResources().getText(R.string.hello_world), Toast.LENGTH_LONG).show();
Run Code Online (Sandbox Code Playgroud)
和:
Toast.makeText(getApplicationContext(), R.string.hello_world, Toast.LENGTH_LONG).show();
Run Code Online (Sandbox Code Playgroud)
似乎在两个方面都有效.
感谢帮助!
Toast.makeText(getApplicationContext(), R.string.hello_world, Toast.LENGTH_LONG)
Run Code Online (Sandbox Code Playgroud)
电话
Toast.makeText(Context, int, int) 并且它被"翻译"了
public static Toast makeText(Context context, int resId, int duration)
throws Resources.NotFoundException {
return makeText(context, context.getResources().getText(resId), duration);
}
Run Code Online (Sandbox Code Playgroud)
总而言之,它等于你的第一个 makeText