码迷,mamicode.com
首页 > 其他好文 > 详细

使用String的几个方法

时间:2016-01-20 00:58:14      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:

Use the String Resources


You can reference your string resources in your source code and other XML files using the resource name defined by the <string> element‘s name attribute.

In your source code, you can refer to a string resource with the syntax R.string.<string_name>. There are a variety of methods that accept a string resource this way.

For example:

// Get a string resource from your app‘s Resources
String hello = getResources().getString(R.string.hello_world);

// Or supply a string resource to a method that requires a string
TextView textView = new TextView(this);
textView.setText(R.string.hello_world);

In other XML files, you can refer to a string resource with the syntax @string/<string_name> whenever the XML attribute accepts a string value.

For example:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

使用String的几个方法

标签:

原文地址:http://www.cnblogs.com/sansansan/p/5143818.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!