一、橫屏時,彈出軟鍵盤不全屏
不知你是否注意到,當我們手機橫屏,且使用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)