Android之EditText特殊小技巧

來源:互聯網
上載者:User

一、橫屏時,彈出軟鍵盤不全屏

不知你是否注意到,當我們手機橫屏,且使用Android內建的軟鍵盤為EditText進行文本輸入時,若不進行特殊的設定,該軟鍵盤會佔用整個介面,那麼,如何讓鍵盤只佔用螢幕的一部分呢? 其實只需要改一個小小的屬性即可!

<EditText     android:id="@+id/text1"     android:layout_width="150dip"     android:layout_height="wrap_content"    android:imeOptions="flagNoExtractUi"/>

 

另外使用android:imeOptinos可對Android內建的軟鍵盤進行一些介面上的設定:

android:imeOptions="flagNoExtractUi"  //使軟鍵盤不全螢幕顯示,只佔用一部分螢幕
同時,這個屬性還能控制項軟鍵盤右下角按鍵的顯示內容,預設情況下為斷行符號鍵
android:imeOptions="actionNone"  //輸入框右側不帶任何提示
android:imeOptions="actionGo"    //右下角按鍵內容為'開始'
android:imeOptions="actionSearch"  //右下角按鍵為放大鏡圖片,搜尋
android:imeOptions="actionSend"    //右下角按鍵內容為'發送'
android:imeOptions="actionNext"   //右下角按鍵內容為'下一步'
android:imeOptions="actionDone"  //右下角按鍵內容為'完成'

 

同時,可能EditText添加相應的監聽器,捕捉使用者點擊了軟鍵盤右下角按鈕的監聽事件,以便進行處理。

 editText.setOnEditorActionListener(new OnEditorActionListener() {@Overridepublic boolean onEditorAction(TextView v, int actionId, KeyEvent event) {Toast.makeText(MainActivity.this, "text2", Toast.LENGTH_SHORT).show();return false;}});

 

 二、修改游標顏色

在使用EditText的XML 檔案中加入一個屬性:

android:textCursorDrawable="@null"

android:textCursorDrawable   這個屬性是用來控制游標顏色的,

"@null"   是作用是讓游標顏色和text color一樣

android:textCursorDrawable 的用法可以查看android sdk

public static final int TextView_textCursorDrawable

 

Reference to a drawable that will be drawn under the insertion cursor.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol textCursorDrawable.

Constant Value: 70 (0x00000046)

 

相關文章

聯繫我們

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