android显示字符的4钟方式
2016-11-27 21:19
239 查看
1、直接在控件定义里面进行赋值(不推荐),如下以显示一个TextView控件为例,其他类似
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/editText2"
android:layout_alignParentLeft="true"
android:text="我的第一个工程,嘻嘻!"
android:textAppearance="?android:attr/textAppearanceMedium" />
2、在主程序里面调用findViewById来进行
TextView text = (TextView) super.findViewById(R.id.textView1);
text.setText("我的第一个Android程序!");
3、在strings里面进行定义,然后在主程序里面使用findViewById来进行调用
<string name="user_name_string">我的第一个工程,嘻嘻!</string>
TextView text = (TextView) super.findViewById(R.id.textView1);
text.setText(R.string.user_name_string);
4、在strings里面进行定义,然后在控件定义里面用@string/xxxxx (推荐使用)
<string name="user_name_string">我的第一个工程,嘻嘻!</string>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/editText2"
android:layout_alignParentLeft="true"
android:text="@string/user_passward_string"
android:textAppearance="?android:attr/textAppearanceMedium" />
5、不使用布局管理器,使用context类创建,先在strings中定义
<string name="user_name_string">我的第一个工程,嘻嘻!</string>
TextView text = new TextView(this);
text.setText(super.getString(R.string.user_name_string));
setContentView(text);
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/editText2"
android:layout_alignParentLeft="true"
android:text="我的第一个工程,嘻嘻!"
android:textAppearance="?android:attr/textAppearanceMedium" />
2、在主程序里面调用findViewById来进行
TextView text = (TextView) super.findViewById(R.id.textView1);
text.setText("我的第一个Android程序!");
3、在strings里面进行定义,然后在主程序里面使用findViewById来进行调用
<string name="user_name_string">我的第一个工程,嘻嘻!</string>
TextView text = (TextView) super.findViewById(R.id.textView1);
text.setText(R.string.user_name_string);
4、在strings里面进行定义,然后在控件定义里面用@string/xxxxx (推荐使用)
<string name="user_name_string">我的第一个工程,嘻嘻!</string>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/editText2"
android:layout_alignParentLeft="true"
android:text="@string/user_passward_string"
android:textAppearance="?android:attr/textAppearanceMedium" />
5、不使用布局管理器,使用context类创建,先在strings中定义
<string name="user_name_string">我的第一个工程,嘻嘻!</string>
TextView text = new TextView(this);
text.setText(super.getString(R.string.user_name_string));
setContentView(text);
相关文章推荐
- android系统开发小问题-启动过程中android字符没有显示出来
- android中的按钮以图片的方式显示_基础篇
- Android 小发现:WebView 显示HTML文本,个别字符出现乱码!
- Android开发:如何设置EditText多行显示输出及改变多行EditText的默认显示方式
- 【Android Training - 09】高效地显示Bitmap图片 [ Lesson 3 - 两种缓存Bitmap的方式 ]
- gridview设置日期类型字符的显示方式
- Android开发---从简单的TextView看Android的控件显示方式
- Android系统开发小问题-启动过程中android字符没有显示出来 .
- 终端对非打印字符的显示方式的有趣例子
- 在Android里显示网页的多种方式
- Android 中图片显示的另一种方式 ImageSwitcher
- android 中超出屏幕宽度的字符 省略号显示
- android系统开发小问题-启动过程中android字符没有显示出来
- android中Textview如何限制在一行显示且多余字符自动截断
- Android全屏显示的两种方式
- android textview 中超出屏幕宽度的字符 省略号显示
- Android——全屏显示的两种方式
- Android 以对话框方式显示Activity
- Android字符高亮显示
- 1.Android开发---从简单的TextView看Android的控件显示方式