The Android soft keyboard blocks the input box and setting adjustResize is not effective. Solution

* adjustPan moves the entire interface upward to expose the input box without changing the layout of the interface;
* adjustResize recalculates the size of the interface after popping up the soft keyboard, which is equivalent to using less interface area to display content. The input box is generally Of course it's inside, the keyboard is blocked

Requirement: Don’t let the layout put the title directly on top, and don’t let the keyboard block the input box.

(1)

After adjustingPan is set, it is OK. The interface is upward as a whole. Why is it invalid to set adjustResize?
It turns out that my Activity extends inherits BaseActivty, so changing it to Activity extends AppCompatActivity is OK.

(2)
 What should I do if BaseActivty has some abstract methods for Activty, or the Base layer has registered EventBus events?
 

/**
 * Created on 2019/12/16.
 * 如果最外层定义的LinearLayout也可以,extends LinearLayout,
   次布局是RelativeLayout。
 */
public class MyRelativeLayout extends RelativeLayout {

    public MyRelativeLayout(Context context) {
        super(context);
    }

    public MyRelativeLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected boolean fitSystemWindows(Rect insets) {
        insets.top = 0;
        return super.fitSystemWindows(insets);
    }

}

 

Replace the root ViewGroup of the original xml layout with our custom ViewGroup, reference it, and set it at the code layer

/**
 * xml层进行调用
 */
<com.test.widget.MyRelativeLayout
    android:layout_width="match_parent"
    android:id="@+id/ly_info"
    android:layout_height="match_parent"/>
/**
 * xml层进行调用
 */
MyRelativeLayout linearLayout = (MyRelativeLayout) findViewById(R.id.ly_info); 
linearLayout.setFitsSystemWindows(true);


 /**
  * 最好在Activity或Fragment销毁时调用linearLayout.setFitsSystemWindows(false);
  * 进行销毁
  */
 @Override
 protected void onDestroy() {
 super.onDestroy();
 ly_info.setFitsSystemWindows(false);
 }
/**
 * 记得在AndroidManifest.xml android:windowSoftInputMode="stateVisible|adjustResize"参数
 */
<activity
     android:name=".test.TestActivity"           
     android:screenOrientation="portrait"
     android:theme="@style/MyAppTheme"
     android:windowSoftInputMode="stateVisible|adjustResize" />
 

 

The personal test was successful. If you have any questions, please let me know.

Guess you like

Origin blog.csdn.net/zyy_give/article/details/103563466