Is it possible to show the Android Snackbar above the keyboard (as in Y coordinate, not layering)? The Snackbar currently gets hidden if the keyboard is shown, which is an undesirable behavior.
-
4Because we couldn't figure this out, we just hide the keyboard whenever we display a snackbar now (which we use for errors) – fobbymaster Oct 19 '16 at 21:55
-
If you have a keyboard, you'll usually get the best experience using a plain old Toast. This will be shown over the keyboard, and you don't need to hide the keyboard (which might confuse the user) – Entreco Jan 14 '18 at 21:35
11 Answers
Set
android:windowSoftInputMode="adjustResize"
in the AndroidManifest.xml
for the activity containing your snackbar

- 2,704
- 27
- 36
-
-
It goes in the AndroidManifest.xml file as an attribute of the Activity in question. – Philip Stratford Dec 19 '16 at 17:18
-
12The issue with this solution is that it also adjusts the entire screen, which isn't something that we want. We only want the snackbar to be adjusted, not the entire screen. – fobbymaster Jan 23 '17 at 21:06
-
I don't know if this is helpful, but I have found that using a DrawerLayuot results in snackbar not showing above the keyboard. If I remove DrawerLayout from the activity, it shows as it should. – dimsuz Jun 30 '17 at 10:19
-
12@fobbymaster, why did you mark this as the answer if as you say "isn't something that we want"? – Awah Teh Oct 18 '17 at 10:39
If you nest your layout in a ScrollView, the snackbar will appear on top of the keyboard. This is because the view will resize to take up only the available space above the keyboard. And, of course, your View will also be scroll-able if necessary at any time, while the keyboard is shown or not.

- 3,560
- 3
- 33
- 48
-
4Using this with android:fillViewport="true" to make sure ScrollView fill the entire screen should be the accepted answer – FallasB Dec 19 '17 at 10:48
You can hide the keyboard when the Snackbar
is shown.
InputMethodManager imm = (InputMethodManager)activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
-
6in case your snackbar is a response to a typing to a textedit this is very unfriendly to user as it could end up with clicking on anything else and unpleasant to see (flickering). better is to nest with scrollviewer – Ivan Nov 13 '17 at 12:57
Jetpack Compose:
Based on androidx.compose.foundation:foundation-layout
documentation
Add
android:windowSoftInputMode="adjustResize"
to yourAndroidManifest.xml
Call
WindowCompat.setDecorFitsSystemWindows(window, false)
in your ActivityonCreate
methodFinally, add
WindowInsets.ime.asPaddingValues()
to your Snackbar'smodifier
like this:
Snackbar(
modifier = modifier
.padding(vertical = 32.dp, horizontal = 16.dp)
.padding(WindowInsets.ime.asPaddingValues()),
...
)

- 3,194
- 2
- 12
- 36
The following works:
- Ensure the activity/fragment from which you are calling the
Snackbar
contains aScrolView
. - Ensure you set the snackbar view to
findViewById(android.R.id.content)
:
Snackbar.make(getActivity().findViewById(android.R.id.content), "hello world").show();
- OR, if you want to be able to swipe away the
Snackbar
, ensure theScrolView
is nested within aCoordinatorLayout
.
Snackbar.make(getActivity().findViewById(android.R.id.my_coordinator_layout), "hello world").show();

- 186
- 1
- 6
I have solved the issue like this:
Create a class:
public class ShowSnackBar {
public static void show(Context context, String message, View view) {
InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show();
}
}
You can access this class from any activity in the application
Usage:
ShowSnackBar.show(LoginOtpActivity.this,"Please enter Email ID /Mobile",linear_container);

- 2,276
- 2
- 20
- 34

- 64
- 6
I had this problem myself and was able to solve it quite easily.
Previously, I had set android:fitsSystemWindows="true"
.
The solution is to set it to false, or just delete that line. Now, you don't need to hide the keyboard to get your desired result.
Here is my layout file for reference:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/relative"
android:orientation="vertical"
android:fitsSystemWindows="false">
<LinearLayout
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_gap"
android:orientation="horizontal">
<EditText
android:id="@+id/input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_weight="1"
android:hint="@string/input_a_number"
android:ems="10"
android:imeOptions="actionDone|flagNoPersonalizedLearning"
android:inputType="numberSigned|numberDecimal"
android:maxLines="1"
android:maxLength="30"
android:singleLine="true"
android:importantForAutofill="no"
android:focusable="true"
android:focusableInTouchMode="true"
android:focusedByDefault="true"
tools:ignore="LabelFor"
tools:targetApi="o" />
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="180dp"
android:layout_marginEnd="@dimen/default_gap"
android:layout_weight="1" />
</LinearLayout>
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/linear"
android:layout_marginEnd="10dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:visibility="gone"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_margin="16dp"
app:elevation="4dp"
app:srcCompat="@drawable/jade"
app:backgroundTint="@color/jade_fab"
android:layout_gravity="bottom|end"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

- 2,131
- 2
- 24
- 36
Jetpack Compose Solution:
in AndroidManifest.xml
add android:windowSoftInputMode="adjustResize"
inside the <activity .. >
.
Then add
Scaffold(snackbarHost = { SnackbarHost(hostState = snackBarHostState, modifier = Modifier.imePadding())}}
also you might need WindowCompat.setDecorFitsSystemWindows(currentWindow, false)
. I placed it in my theme.kt
Lastly, the OutlinedTextField()
and the snackBarHostState/snackbar should show on top of the soft or on screen keyboard. (you might need modifier.imePadding() for the OutlinedTextField()
as well)

- 31
- 4
-
It looks like `Modifier.imePadding()` isn't even necessary, at which point, this is the same as the answer from giorgos.nl which has the most votes. – Kevin Worth Aug 29 '23 at 19:28
This is my code for snackbar and its working similarly+ as you need relativeLayout is the parent main layout id i have passed.
snackbar=snackbar.make(relativeLayout,"Image is Saved to "+Savedfile.getPath().toString(),Snackbar.LENGTH_INDEFINITE)
.setAction("OK", new OnClickListener() {
@Override
public void onClick(View v) {
snackbar.dismiss();
snackbar=null;
System.gc();
finish();
}
});
snackbar.show();

- 1
this is my code , there is no need to set view from method , you can get it from DecoreView :
public static void longSnack(final String text) {
hideKeyboard();
Snackbar snackbar = Snackbar.make(context.getWindow().getDecorView(), text, Snackbar.LENGTH_LONG);
snackbar.show();
}
public static void shortSnack(final String text) {
hideKeyboard();
Snackbar snackbar = Snackbar.make(context.getWindow().getDecorView(), text, Snackbar.LENGTH_SHORT);
snackbar.show();
}
private static void hideKeyboard() {
InputMethodManager inputMethodManager = (InputMethodManager)context.getSystemService(Activity.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
inputMethodManager.hideSoftInputFromWindow(context.getWindow().getDecorView().getWindowToken(), 0);
}
}
-
Please provide some context on why your code is a valid answer. Please see https://stackoverflow.com/help/how-to-answer – Marcello B. Sep 13 '19 at 00:57
Add snack bar in this way, place a Container @ content argument, with padding from bottom of Keyboard size.
SnackBar snackBar =
SnackBar(
content: Container(
padding: EdgeInsets.only( bottom:
MediaQuery.of(context).viewInsets.bottom),
child: Text('Please add your quote !!!')),
duration: Duration(milliseconds: 800),
);
// Add this given line in function body where to show snack bar
ScaffoldMessenger.of(context.showSnackBar(snackBar);

- 19
- 2
-
As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 31 '22 at 10:27