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=""
        />

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM