How to keep toolbar visible using Pan setting?

I have a layout similar to the one below, and I would like to have the following behavior when the user clicks on an EditText:

  • The keyboard should overlay "LinearLayout aligned at the bottom";
  • EditText should be visible on the screen, not a keyboard overlay;
  • The toolbar should be visible on the screen;

My layout

enter image description here

Expected Behavior

enter image description here

Actual result using windowSoftInputMode = adjustPan

Requirements not met:

  1. The toolbar should be visible on the screen;

enter image description here

Actual result using windowSoftInputMode = adjustResize

Requirements not met:

  • The keyboard should overlay "LinearLayout aligned at the bottom";

enter image description here

Actual result using windowSoftInputMode = adjustNothing

Requirements not met:

  1. EditText should be visible on the screen, not a keyboard overlay;

enter image description here

Has anyone encountered the same problem and made demands?

+8
android layout keyboard android-toolbar
source share
3 answers

I'm not sure if there is any of the window solutions to make it work as you expect.

However, you can achieve the specified behavior by using windowSoftInputMode = adjustNothing and setting the focus listener to edit the text and scrolling scroll when the editing text gets focus.

If it is not clear how to implement scrolling, I can add an example.

0
source share

I think there is no easy way to achieve this. but there is a project here that has a SizeNotifierRelativeLayout then pops up when the keyboard is opened.

0
source share

Change the parent layout to Relative layout

 public class SizeNotifierRelativeLayout extends RelativeLayout { private Rect rect = new Rect(); public SizeNotifierRelativeLayoutDelegate delegate; public abstract interface SizeNotifierRelativeLayoutDelegate { public abstract void onSizeChanged(int keyboardHeight); } public SizeNotifierRelativeLayout(Context context) { super(context); } public SizeNotifierRelativeLayout(android.content.Context context, android.util.AttributeSet attrs) { super(context, attrs); } public SizeNotifierRelativeLayout(android.content.Context context, android.util.AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } /** * Calculate the soft keyboard height and report back to listener * @param changed * @param l * @param t * @param r * @param b */ @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); if (delegate != null) { View rootView = this.getRootView(); int usableViewHeight = rootView.getHeight() - AndroidUtilities.statusBarHeight - AndroidUtilities.getViewInset(rootView); this.getWindowVisibleDisplayFrame(rect); int keyboardHeight = usableViewHeight - (rect.bottom - rect.top); delegate.onSizeChanged(keyboardHeight); } } 

Further in your activity or fragment contains the following codes

  private SizeNotifierRelativeLayout sizeNotifierRelativeLayout; View rootView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); rootView = view.findViewById(R.id.root); sizeNotifierRelativeLayout = (SizeNotifierRelativeLayout) view.findViewById(R.id.chat_layout); sizeNotifierRelativeLayout.delegate = this; rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Rect r = new Rect(); rootView.getWindowVisibleDisplayFrame(r); int screenHeight = rootView.getRootView().getHeight(); int keypadHeight = screenHeight - r.bottom; Log.d("Height", "keypadHeight = " + keypadHeight); if (keypadHeight > screenHeight * 0.15) { // 0.15 ratio is perhaps enough to determine keypad height. // keyboard is opened if (sizeNotifierRelativeLayout != null) { sizeNotifierRelativeLayout.setPadding(0, 0, 0, keypadHeight - 200); } } else { // keyboard is closed if (sizeNotifierRelativeLayout != null) { sizeNotifierRelativeLayout.post(new Runnable() { public void run() { if (sizeNotifierRelativeLayout != null) { sizeNotifierRelativeLayout.setPadding(0, 0, 0, 0); } } }); } try { } } catch (NullPointerException e) { e.printStackTrace(); System.out.print(e.getMessage()); } } } }); } 
0
source share

All Articles