android 读取资源字符串的 方法
16lz
2021-01-23
字符串资源的定义
文件路径:res/values/strings.xml
字符串资源定义示例:
<? xml version="1.0" encoding="utf-8" ?>< resources >
< string name ="hello" > Hello! string >
resources >
字符串资源的调用
在 Layout XML 调用字符串资源:
< TextViewandroid:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:text ="@string/hello" />
在 Activity 获取字符串资源:
this .getString(R.string.hello)
从 Context 获取字符串资源:
context.getString(R.string.hello)
从 Application 获取字符串资源:
application.getString(R.string.hello)参考:
String Resources
作者:黎波
博客: http://bobli.cnblogs.com/
日期:2011年6月4日
更多相关文章
- Android中RatingBar的自定义总结
- android 自定义view支持gif格式播放
- 【Android】ToolBar设置NavigationIcon不显示异常或自定义失败异
- Android开发便签9:在android资源文件中定义字符串数组
- android 自定义水平和圆形progressbar 只定义一些style就可以
- Android frameworks添加资源后编译报错:找不到添加的内部资源 com
- Android 更改 Toast 的默认位置及自定义Toast
- 我的android 第20天 - 自定义适配器
- Android开发必备的免费资源和工具