因需自定義鍵盤油宜,系統(tǒng)鍵盤則需要隱藏,但是EditText的光標(biāo)又需要存在~~~
嘗試了n中屬性配置怜姿,依然不得解慎冤,百度n種,依然無效沧卢,可想我內(nèi)心是多么奔潰的蚁堤,一個(gè)小功能,耗費(fèi)如此精力??
最終 :皇天不負(fù)有心人啊但狭,查閱各種违寿,終于解決
/**
* 強(qiáng)制隱藏系統(tǒng)軟鍵盤,不夠EditText是否點(diǎn)擊都隱藏
*
* @param v
* @param context
*/
public static void HideKeyboard(EditText v, Activity context) {
context.getWindow().setSoftInputMode
(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
int currentVersion = android.os.Build.VERSION.SDK_INT;
String methodName = null;//4.0以上和4.2以上方法名有所改變
if (currentVersion >= 16) {
// 4.2
methodName = "setShowSoftInputOnFocus";
} else if (currentVersion >= 14) {
// 4.0
methodName = "setSoftInputShownOnFocus";
}
if (methodName == null) {//4.0以下采用此方法
v.setInputType(InputType.TYPE_NULL);
} else {
Class<EditText> cls = EditText.class;
Method setShowSoftInputOnFocus;
try {
setShowSoftInputOnFocus = cls.getMethod(methodName, boolean.class);
setShowSoftInputOnFocus.setAccessible(true);
setShowSoftInputOnFocus.invoke(v, false);
} catch (NoSuchMethodException e) {
v.setInputType(InputType.TYPE_NULL);
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}