Android开发之四(一):常用控件之文本框TextView

来源:互联网 发布:mysql 清空数据表 编辑:程序博客网 时间:2024/05/21 10:59

TextView就是一个用来显示文本内容的控件,可以通过xml布局配置文件或者硬编码的方式设置该控件的各个属性;

TextView的使用就是首先在xml布局文件声明一个TextVeiw对象,然后在代码中通过ID获取该TextView对象,接着对TextView对象进行其他的操作。


关于TextView的简单了解:


在xml布局文件中的声明方式:

    <TextView  
    android:id="@+id/textview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />


关于TextView的简单编码方式:

/* 声明TextView对象 */private TextView textview;        /*TextView要显示的文本*/                String string = "TextView示例";/* 设置文本的颜色 */        textview.setTextColor(Color.RED);/* 设置字体大小 */textview.setTextSize(20);/* 设置文字背景 */textview.setBackgroundColor(Color.BLUE);/* 设置TextView显示的文字 */textview.setText(string);