您的位置:首页 > 移动开发 > Android开发

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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android字符显示