安卓介面組件-文字框

來源:互聯網
上載者:User

標籤:開發   分享   效果   ble   子類   相關   otto   input   設計   

    前面三篇文章本質上是圍繞著View類進行的。View是安卓UI的基礎類,我們的安卓開發“千裡之行”是從View開始的。

    安卓介面UI有大量的組件,組件的繼承和間接繼承於View。有一類組件很基本,這就是TextView文字框,作用是顯示文本。在TextView基礎上,TextView派生出:EditText CheckedTextView Button DigitalClock Chronometer等幾個子類控制項,強化了TextView的功能。這一節介紹一下TextView和EditText類

一  EditText

    EditText屬性:

                       android:autoLink     將文本轉換為可點擊的超連結形式,取值:none web email phone map all

                       android:drawableBottom      在文本下方繪製圖片,類似的屬性還有android:drawableLeft  android:drawableTop  android:drawableRight

                       android:gravity        顯示文本的對其方式

                       android:inputType    文本輸入形式

                       android:hint             提示

                       android:textColor     文本顏色

實際操作:設計出超連結形式文本和有圖片文本,多行文本

請閱讀xml,找出設定上面文字框效果的屬性

        <TextView            android:id="@+id/textView1"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:autoLink="email"            android:text="@string/mail" />        <TextView            android:id="@+id/textView2"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:drawableBottom="@drawable/ic_launcher"            android:text="@string/icon" />        <TextView            android:id="@+id/textView3"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:singleLine="false"            android:text="@string/longText" />
二    編輯框

     編輯框的作用是在螢幕進行文本編輯,實際上是TextView開啟文本編輯功能形成的組件。EditText的特殊屬性肯定是和文本編輯有關,相關屬性如下

     EditText屬性:

                         android:inputType      輸入文本類型,基本類型有密碼,電話等等;可以通過ctrl + /查看

                         android:singleLine      是否單行輸入

實際操作:製作一個註冊介面

相關xml代碼如下,比較簡單

    <TableLayout        android:layout_width="match_parent"        android:layout_height="match_parent" >        <TableRow            android:id="@+id/tableRow1"            android:layout_width="wrap_content"            android:layout_height="wrap_content" >            <TextView                android:id="@+id/textView1"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="姓名:" />            <EditText                android:id="@+id/editText1"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:ems="10"                android:inputType="textPersonName" >                <requestFocus />            </EditText>        </TableRow>        <TableRow            android:id="@+id/tableRow2"            android:layout_width="wrap_content"            android:layout_height="wrap_content" >            <TextView                android:id="@+id/textView2"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="屬兔密碼:" />            <EditText                android:id="@+id/editText2"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:ems="10" />        </TableRow>        <TableRow            android:id="@+id/tableRow3"            android:layout_width="wrap_content"            android:layout_height="wrap_content" >            <TextView                android:id="@+id/textView3"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="確認密碼:" />            <EditText                android:id="@+id/editText3"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:ems="10" />        </TableRow>        <TableRow            android:id="@+id/tableRow4"            android:layout_width="wrap_content"            android:layout_height="wrap_content" >        </TableRow>        <Button            android:id="@+id/button1"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="提交" />    </TableLayout>

總結:以上是安卓基本文本控制項,用於介面文本顯示。

        水平有限,請留言!

 

安卓介面組件-文字框

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.