0%

Android UI设计 文本控件TextView用法

文本控件TextView用法: main.xml中:

<TextView android:id="@+id/result"
    <!--设定ID为result,此项可选-->
    android:layout_width="fill_parent" 
    <!--宽度为填满父容器-->
    android:layout_height="wrap_content"
    <!--高度为自动根据内容调整-->
    android:text="@string/height"
    <!--文本控件内容为string.xml中的height-->
    />

string.xml中的height:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="height">身高</string>
</resources>

在程序中修改显示的文本:

private TextView result;
result=(TextView)findViewById(R.id.report_result);
result.setText(CharSequence text);

另外,一直没搞懂CharSequence和String的区别,JAVA手册上定义CharSequence 是 char 值的一个可读序列,此接口对许多不同种类的 char 序列提供统一的只读访问。但在用法上跟String貌似差不多,有了解的兄弟希望能指教下。 setText方法还支持Resources ID,即可以在xml文件中定义字符串,然后在setText(int resid)引用。TextView不支持HTML标签,但如果需要显示链接,可以在布局xml中加入android:autoLink属性,详见在TextView中显示链接 定义颜色