今天老大安排了一个任务,开发一个自定义键盘,并且禁用webView的输入框焦点会自动弹出输入法的功能
过程不多说--->实践
-----------------》
1.先取出当前fragment的fragment
/*** 取出当前焦点的Fragment*/public BaseWebFragment getVisibleFragment(FragmentManager mManagers) {FragmentManager fragmentManager = mManagers;List<Fragment> fragments = fragmentManager.getFragments();for (Fragment fragment : fragments) {if (fragment != null && fragment.isVisible())return (BaseWebFragment) fragment;}return null;}
2.一个工具类
/*** Created by kaiyuan on 16/5/31.*/public class KeyboardUtil {public static void hideKeyboard(Context context, View view) {InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);imm.hideSoftInputFromWindow(view.getWindowToken(), 0);}public static void showKeyboard(Context context, View view) {InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);imm.showSoftInput(view, 0);}}
3.在显示自定义键盘的时候处理
final WebView wv= fobjm.getVisibleFragment(fobjm.getFragmentManager()).getWebView();new Handler().post(new Runnable() {@Overridepublic void run() {wv.setVisibility(View.VISIBLE);wv.requestFocus();KeyboardUtil.hideKeyboard(context, wv);mKeyboardManager.show();}});
---------》
mKeyboardManager
这个是我们自己开发的键盘了,你们在这里调用你们写的键盘显示方法就可以了