android EditText多行文本輸入的若干問題

來源:互聯網
上載者:User

標籤:android   edittext   textmultiline   

以前習慣了網頁以及swing上的文字框輸入,現在到Android上突然沒有了這種控制項,剛開始使用起來還是比較費力的。為了想實現多行文字框的輸入及顯示效果,逐一解決了如下問題:

1. 如何讓EditText顯示成為一個文字框的地區用來輸入;

2. 游標從首行開始顯示;

3. 如何是設定捲軸;

4. 如何固定文字框的大小。

5. 如何讓文字框顯示邊線;

為了達到如下的效果,我們做了如下的工作:


<EditText    android:id="@+id/add_content"    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:enabled="true"    android:gravity="top"    android:inputType="textMultiLine"    android:minLines="8"    android:maxLines="10"    android:scrollbars="vertical"     android:background="@android:drawable/edit_text"    ></EditText>

上面 是這個控制項效果的xml。

一下兩行用來顯示輸入地區的效果;

    android:inputType="textMultiLine"    android:minLines="8"

android:background="@android:drawable/edit_text"  <!-用來顯示控制項的邊線->
 android:maxLines="10"    android:scrollbars="vertical" 
以上兩行用來設定地區的最大行數是10,超過10行之後會以“豎直捲軸”的形式顯示。

 android:gravity="top"  <!-用來設定游標的起始位置從頂行開始,否則預設情況下是從中間行開始->


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.