前言
平時(shí)開發(fā)中經(jīng)常遇到的小的問題潜必,這里記錄一下殖氏。
EditText禁止自動(dòng)彈出軟鍵盤的方法
在包含EditText的父布局中添加android:focusable="true"
和android:focusableInTouchMode="true"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
>
<EditText
android:id="@+id/edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:maxLines="1"
/>
</LinearLayout>
ScrollView默認(rèn)位置不是最頂部解決方案
跟EditText一樣,在父元素的屬性這兩行即可android:focusable="true"
和android:focusableInTouchMode="true"
進(jìn)入頁面讓EditText自動(dòng)彈出鍵盤
/**
* 打開軟鍵盤
*
* @param view
*/
public static void openKeybord(final View view) {
view.postDelayed(new Runnable() {
@Override
public void run() {
((InputMethodManager) view.getContext().getSystemService(
Context.INPUT_METHOD_SERVICE)).toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
}
},100);
}
目前測(cè)試此方法在頁面初始化調(diào)用不能自動(dòng)打開鍵盤闻鉴,但在點(diǎn)擊事件中可以打開