如果你想清除默認專注於編輯文本,然後使用下面的兩個屬性
android:focusable="false"
android:focusableInTouchMode="true"
父線性佈局內。
例如:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="true"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="email id"
android:inputType="textEmailAddress"
android:maxLines="1"
/>
</LinearLayout>
如果你想隱藏的活動創造鍵盤使用清單文件活動標籤 內這些屬性,例如:如果要隱藏鍵盤
<activity
android:configChanges="screenSize|orientation|keyboardHidden"
android:screenOrientation="portrait"
android:name=".activities.LoginActivity"
android:windowSoftInputMode="stateHidden|adjustResize"/>
點擊按鈕或發生某些事件時使用以下代碼
public void onClick(View v) {
try {
//InputMethodManager is used to hide the virtual keyboard from the user after finishing the user input
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm.isAcceptingText()) {
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}
} catch (NullPointerException e) {
Log.e("Exception", e.getMessage() + ">>");
}
}
} catch (NullPointerException e) {
Log.e("Exception", e.getMessage() + ">>");
}
如果你想脫下從編輯文本字段的焦點離開活動後
@Override
protected void onResume() {
super.onResume();
mEmail.clearFocus();
mPassword.clearFocus();
}
最後如果你想清除表單提交使用
@Override
protected void onResume() {
super.onResume();
mEmail.getText().clear();
mPassword.getText().clear();
}
集的Android窗口軟輸入模式:可調焦=「假」。它不會專注於您的EditText –
,這將永遠不可用?現在即使我點擊文字欄也不會關注。我想要點擊時的焦點,只是不會自動當應用程序啓動 – Saad
您可以先獲取按鈕的ID,並設置您的代碼中的按鈕焦點.... – Hanry