Suppose the rootView of your layout is RelativeLayout. What you can do is create a CustomRelativeLayout class that extends RelativeLayout and overrides the onSizeChanged method inside it. Therefore, when the soft keyboard opens, the height of the RelativeLayout will change, and this will be reported in the onSizeChanged method.
public class CustomRelativeLayout extends RelativeLayout { @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); int softKeyboardHeight = oldh - h;
In the manifest file, make these changes so that the action opens in resize mode rather than in pan and scan mode. In resize mode, the layout will be able to resize when the keyboard is opened. To learn more about pan scanning and resizing, visit https://developer.android.com/training/keyboard-input/visibility
<activity android:name=".MainActivity" android:windowSoftInputMode="adjustResize"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
Prashuk Jain Apr 24 '19 at 19:10 2019-04-24 19:10
source share