Android strings.xml空格占位符及其使用方法

1、各种空格占位符。

 (普通的英文半角空格)
 (普通的英文半角空格但不换行)
 (中文全角空格,就是一个中文宽度)
 (半个中文宽度)
 (一个中文宽度)
 (四分之一中文宽度)

<!-- 以半个中文宽度的空格为例,其引入方式 -->
<string name="created_b">创建了&#8194;</string>

2、在布局文件(xml文件)中的使用。


    <TextView
        android:id="@+id/tev_create_user"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:layout_gravity="center"
        android:background="@color/color_FFFFC73B"
        android:gravity="center"
        android:includeFontPadding="false"
        android:paddingStart="@dimen/dp_15"
        android:paddingTop="@dimen/dp_10"
        android:paddingEnd="@dimen/dp_15"
        android:paddingBottom="@dimen/dp_10"
        android:text="@string/user_b"
        android:textColor="@color/color_FFFFFF"
        android:textSize="@dimen/sp_16" />

3、在java代码中的使用。

//初始化TextView
TextView tevTitle = (TextView) findViewById(R.id.tev_title);
//使用方法
tevTitle.setText(getResources().getString(R.string.user_b));

猜你喜欢

转载自blog.csdn.net/NakajimaFN/article/details/127013407