【2021】Week Bug Summary (1st Issue)

1. Huawei mobile phone Android9.0 or above security keyboard blocks Toast problem

Severity: ★☆

If the EditText is set to inpuType=”textPassword” and the focus is on the EditText, the pop-up Huawei security keyboard will block the Toast prompt.

Solution:

Option 1. Click the button and let other views get the focus;

Scheme 2. Hide the safety keyboard when clicking the button;

/** * display soft keyboard */ fun showKeyboard(view: view) {val imm: InputMethodManager = view.context .getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager if (imm ! = null) {view.requestFocus() imm.showsoftinput (view, 0)}} /** * hide soft keyboard */ fun hideKeyboard(view: View) { val imm = view.context .getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager imm? .hideSoftInputFromWindow(view.windowToken, 0) }Copy the code

Option 3: Essentially hide the keyboard

// Solve the Toast problem with Huawei security keyboard Activity) { if (Build.MANUFACTURER == "huawei") { val findFocus = activity.window.decorView.findFocus() if (findFocus is  EditText) { var editText = findFocus if ((editText.inputType == (InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT)) or (editText.inputType == (InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD))) { val systemService: InputMethodManager = activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager systemService.hideSoftInputFromWindow(editText.windowToken, InputMethodManager.HIDE_NOT_ALWAYS) } } } }Copy the code

Tips: Execute this method via view.post.

2.EditText password mode setOnKeyListener Millet security keyboard keyevent. KEYCODE_DEL No return value problem

Severity: ★★★☆

In the custom control, EditText password mode listen setOnKeyListener xiaomi security keyboard keyevent. KEYCODE_DEL no return value problem, resulting in unable to call back keyboard events, delete displayed text.

et.setOnKeyListener { _, keyCode, event -> if (keyCode == KeyEvent.KEYCODE_DEL && event.action == KeyEvent.ACTION_DOWN && codes.size > 0) { codes.removeAt(codes.size - 1) setTextViews() block? .invoke((codes.size == 6)) true } else { false } }Copy the code

Solution: Since it is the security measures of mi security keyboard, it can only be adjusted according to demand. A custom control is a custom control that inputs a verification code, listens for the deletion of EditText content, and controls the display of multiple TextView content.

Option 1. Change the InputType of EditText from Android: InputType =”numberPassword” to Android: InputType =”number”

Scheme 2: Directly listen to the EditText content changes, through addTextChangedListener back and forth TextView content.

3. The problem that the nested RecyclerView in NestedScrollView automatically slides to the bottom after switching

Severity: ★★☆

Problem Description: The main Activity is composed of Activity + four fragments. The home page Fragment uses NestedScrollView nested with other Views + RecyclerView. When switching from the home page Fragment to another Fragment, After switching back to huawei, the home page Fragment will automatically slide to the bottom.

1. It may be easy to grab the focus of RecyclerView, so that it slides to the first item of RecyclerView every time. 2. The sliding problem may be caused by the layout_behavior set by the previous nesting of CoordinatorLayout + NestedScrollView on NestedScrollView.

Solution:

For 1: since RecyclerView dominates the focus, set the focus manually at the top of the NestedScrollView. Add these two attributes to the first sublayout under NestedScrollView:

android:descendantFocusability="blocksDescendants"
android:focusable="true"
android:focusableInTouchMode="true"
Copy the code

For 2: Remove the layout_behavior set to NestedScrollView.