Reputation: 281
MY CODE (and more): I have a Coordinator Layout as follows
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="280dp"
android:fitsSystemWindows="true"
app:contentScrim="@color/transparent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<include layout="@layout/top" /> <!-- A RelativeLayout -->
<android.support.v7.widget.Toolbar
android:id="@+id/MyToolbar"
android:layout_width="match_parent"
android:layout_height="64dp"
app:layout_collapseMode="parallax">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<!-- Main content here -->
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
Inside the frame layout I am inflating a custom view with an edit text which is placed at the bottom. The edit text and custom view show up fine.
I have defined android:windowSoftInputMode="adjustResize|stateHidden" in the manifest.
MY PROBLEM: While tapping on the edit text to bring up the softkeyboard, it overlaps the content beneath instead of resizing the FrameLayout. I just could not get the FrameLayout to resize when the soft keyboard comes up. Any help will be appreciated
THINGS I TRIED:
Upvotes: 28
Views: 13963
Reputation: 350
For now I am solving it using androidx.drawerlayout.widget.DrawerLayout to wrap:
CoordinatorLayout, AppBarLayout, CollapsingToolbarLayout, Toolbar, NestedScrollView
It is maybe not the best idea but it is working for me ;)
I have a sample in my project: https://github.com/maiconpintoabreu/Kupping-Mobile/blob/master/app/src/main/res/layout/activity_event_new.xml
Upvotes: 0
Reputation: 59
Don't use CoordinatorLayout as a root layout if you use EditText views on your NestedScrollView
<androidx.constraintlayout.widget.ConstraintLayout
android:fitsSystemWindows="true">
<androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.appbar.CollapsingToolbarLayout/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView>
<Editext/>
<androidx.core.widget.NestedScrollView/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Upvotes: 6
Reputation: 484
A shortened version from KeyboardUtil, add this to your activity:
getWindow().getDecorView().getViewTreeObserver()
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
Rect r = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
rootView.setPadding(0, 0, 0,
activity.getResources().getDisplayMetrics().heightPixels - r.bottom);
}
});
Upvotes: 1
Reputation: 20617
I'm using this for solving CoordinatorLayout bug
in onCreateDialog in BottomSheetFragment
KeyboardUtil(getActivity(), view);
or
For Activity use
new KeyboardUtil(this, findViewById(R.id.fragment_container));
by using this Util class
Kotlin version: https://gist.github.com/agustinsivoplas/6f80233699aebebd512542503ea32682 Credit:Mikepenz,Agustinsivoplas
Upvotes: 10
Reputation: 21
adjustResize not work with
app:layout_behavior="@string/appbar_scrolling_view_behavior"
Remove this line:
app:layout_behavior="@string/appbar_scrolling_view_behavior"
Upvotes: 2
Reputation: 4330
This is just another bug in the design support lib and it seems they don't plan to fix it any time soon:
Confirmed, but probably won't be fixed any time soon. adjustResize has a few good use-cases, but using AppBarLayout with CollapsingToolbarLayout with it is not one of them.
It's disturbing that nobody tried to add a EditText
to a CoordinatorLayout
with android:windowSoftInputMode="adjustResize"
while developing the design support lib.
Upvotes: 18
Reputation: 69
Hi I had the same problem and I only put
android:windowSoftInputMode="adjustPan"
in yout manifest for the activity concerned and the keyboard moves up the view accordingly now
Upvotes: 2
Reputation: 9904
Try this
your_layout.xml
<RelativeLayout
android:fitsSystemWindows="true" > <!-- Crucial! -->
<android.support.design.widget.CoordinatorLayout>
...
<android.support.v7.widget.RecyclerView />
...
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>
AndroidManifest.xml
<activity
android:name=".YourActivity"
android:windowSoftInputMode="adjustResize"> <!-- Crucial! -->
</activity>
Upvotes: 17
Reputation: 131
My Layout
<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout>
<android.support.design.widget.CollapsingToolbarLayout>
<ImageView>
<android.support.v7.widget.Toolbar>
<android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton>
<android.support.design.widget.CoordinatorLayout>
I had the exact same problem. I figured out, that if i use something within the e.g. NestedScrollView
or within a FrameLayout
i would assume as well that handles the Scroll itself, the CoordinatorLayout
does not adjustResize
/ behave the way you want. The adjustResize|adjustPan settings within the Manifest are ignored.
For me this was very hard to figure out, because i wrote a few (combined-) Views myself that contained RelativeLayout
or ScrollViews
and such.
If i just avoid using RelativeLayouts
or anything else than NestedScrollView
to handle the view scrolling, it behaves the way, at least i wanted it to.
But i think, there is a Bug within CoordinatorLayout
or a behaviour we all need to understand better to avoid this type of problems...
Maybe this is useful to know for someone...
My Settings are:
Upvotes: 7