Android学习之路一:TextView和EditView
TextView(文本框)是Android系统中最常见的控件之一,使用TextView可生成一段文本文字,合理使用TextView的属性还能使文字变得有姿有色。
TextView控件可以通过XML文件设置全部属性,也可以通过Java代码设置属性。
java代码:
//获得TextView控件 TextView myText = (TextView) findViewById(R.id.myText); //调用set方法设置属性 myText.setTextColor(Color.BLUE);//设置文件的颜色为蓝色 myText.setTextSize(25);//设置文本的字体大小为25dp
XML代码:
<TextView android:id="@+id/myText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello_world" android:textColor="#00f" android:textSize="20dp"/>
EditView是Android系统中的编辑框,可以理解为可编辑的TextView,用法和属性都和TextView相似。
java代码:
EditText myEdit = (EditText)findViewById(R.id.myEdit); myEdit.setHint("请输入文字"); myEdit.setCursorVisible(true); myEdit.setTextColor(Color.BLUE);
XML代码:
<EditText android:id="@+id/myEdit" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="" />