Browse Source

fix 小键盘收起问题

lihao1 3 years ago
parent
commit
c661c8a7e6

+ 2 - 2
demo/src/main/java/com/sybotan/android/demo/activities/EquipDetailActivity.kt

@@ -123,8 +123,8 @@ class EquipDetailActivity : BaseActivity(), View.OnTouchListener {
         }
 
     override fun onCreate(savedInstanceState: Bundle?) {
+        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
         super.onCreate(savedInstanceState)
-        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
         setContentView(R.layout.activity_equip_detail)
         initView()
         initData()
@@ -240,7 +240,7 @@ class EquipDetailActivity : BaseActivity(), View.OnTouchListener {
             )
         }
         findViewById<ImageView>(R.id.back).setOnClickListener { finish() }
-        root.setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY -> dismissSoftKeyboard() }
+//        root.setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY -> dismissSoftKeyboard() }
         if (!TextUtils.isEmpty(deviceId)) {
             location.setOnClickListener {
                 EventBus.getDefault().postSticky(ReLoactionEventBus(equip))

+ 24 - 24
demo/src/main/java/com/sybotan/android/demo/adapter/StaticInfoAdapter.java

@@ -342,30 +342,30 @@ public class StaticInfoAdapter extends BaseRecyclerViewAdapter<Infos> {
         editText.addTextChangedListener(textWatcher);
         editText.setTag(textWatcher);
 
-//        editText.getViewTreeObserver().addOnGlobalLayoutListener(
-//                () -> {
-//                    Rect r = new Rect();
-//                    editText.getWindowVisibleDisplayFrame(r);
-//                    int screenHeight = editText.getRootView()
-//                            .getHeight();
-//                    int heightDifference = screenHeight - (r.bottom);
-//                    if (heightDifference > 200) {
-//                        //软键盘显示
-//                        editText.setFocusable(true);
-//                    } else {
-//                        //软键盘隐藏
-//                        editText.clearFocus();
-//
-//                    }
-//                });
-//        editText.setOnClickListener(v -> {
-//            editText.setFocusable(true);
-//            editText.setFocusableInTouchMode(true);
-//            editText.requestFocus();
-//            editText.findFocus();
-//            InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
-//            imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);// 显示输入法
-//        });
+        editText.getViewTreeObserver().addOnGlobalLayoutListener(
+                () -> {
+                    Rect r = new Rect();
+                    editText.getWindowVisibleDisplayFrame(r);
+                    int screenHeight = editText.getRootView()
+                            .getHeight();
+                    int heightDifference = screenHeight - (r.bottom);
+                    if (heightDifference > 200) {
+                        //软键盘显示
+                        editText.setFocusable(true);
+                    } else {
+                        //软键盘隐藏
+                        editText.clearFocus();
+
+                    }
+                });
+        editText.setOnClickListener(v -> {
+            editText.setFocusable(true);
+            editText.setFocusableInTouchMode(true);
+            editText.requestFocus();
+            editText.findFocus();
+            InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
+            imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);// 显示输入法
+        });
     }
 
     @Override