Android development keyboard pop-up

How to pop up the soft keyboard


1. Set when the activity is registered
<activity android:name="com.zwg.xjkb.RegisterActivity"
            android:windowSoftInputMode="stateAlwaysVisible">
</activity>


2. Call and hide with code


The first thing to do is to find the component on which the soft keyboard pops up
Secondly, the delay effect is that when the soft keyboard pops up just after entering a page, it may not be possible to detect the delay processing at this time. Instead, do not delay processing
tv_inname = (EditText) view.findViewById(R.id.tv_inname);
tv_inname.requestFocus();




UIUtils.getHandler().postDelayed(new Runnable() {
@Override
public void run() {
InputMethodManager manager=(InputMethodManager) tv_inname.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
manager.showSoftInput(tv_inname, 0);

}
}, 100);




// This display does not require deferred processing. However, on some mobile phones, delay processing is still required to be displayed, so the final solution still needs delay processing;
manager.showSoftInput(qSearchView.et_searchcontent, InputMethodManager.SHOW_FORCED);




//hide
manager.hideSoftInputFromWindow(view.getWindowToken(), 0);//Hide the input keyboard.


3. The pop-up keyboard is divided into two types of screens, moving up or the keyboard is covered on the screen (the default is moving up)


getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);//覆盖
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);//上移


<activity android:name="com.zwg.xjkb.RegisterActivity"
            android:windowSoftInputMode="adjustPan">//覆盖
</activity>


<activity android:name="com.zwg.xjkb.RegisterActivity"
            android:windowSoftInputMode="adjustResize">//屏幕上移
</activity>
4. Disable pop-up keyboard


et.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
hideSoftInputMethod(et);
return false;
}
});


/**
* Disable the system soft keyboard
*/
public void hideSoftInputMethod(EditText mEdit) {
mActivity.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
int currentVersion = android.os.Build.VERSION.SDK_INT;
String methodName = null;
if (currentVersion >= 16) {
// 4.2
methodName = "setShowSoftInputOnFocus";
} else if (currentVersion >= 14) {
// 4.0
methodName = "setSoftInputShownOnFocus";
}
if (methodName == null) {
mEdit.setInputType(InputType.TYPE_NULL);
} else {
Class<EditText> cls = EditText.class;
Method setShowSoftInputOnFocus;
try {
setShowSoftInputOnFocus = cls.getMethod(methodName,
boolean.class);
setShowSoftInputOnFocus.setAccessible(true);
setShowSoftInputOnFocus.invoke(mEdit, false);
} catch (NoSuchMethodException e) {
mEdit.setInputType(InputType.TYPE_NULL);
e.printStackTrace ();
} catch (IllegalAccessException e) {
e.printStackTrace ();
} catch (IllegalArgumentException e) {
e.printStackTrace ();
} catch (InvocationTargetException e) {
e.printStackTrace ();
}
}
}
5. Configure in the AndroidManifest file not to play, but click it will play


<activity  
           android:name="smalt.manger.sms.SmsShowDetailItemsActivity"  
           android:windowSoftInputMode="stateHidden|stateAlwaysHidden" >  
       </activity>  
6. There is no focus directly set in editText, click is to give focus to the past




//Start display without cursor, can't focus, no focus
android:focusable="false"  
            android:focusableInTouchMode="false"  

//Click to focus, touch to focus, apply for focus
et_search.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               tv_search.setFocusable(true);//Set the input box to be aggregated
               tv_search.setFocusableInTouchMode(true);//Set touch focus
               tv_search.requestFocus();//Request focus
              // tv_search.findFocus();//Get the focus
           }
       });


//After the operation is completed, the setting cannot be focused, and it can be operated when clicked.
tv_search.setFocusable(false);//Set the input box to be aggregated

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324470047&siteId=291194637