I am using snack bar for displaying information, it is working fine if keyboard is not opened. If keyboard is opened the snack bar message displaying whole screen not displaying properly i am using android 5.5. I added this line android:windowSoftInputMode="adjustResize|stateAlwaysHidden" in my activity manifest but still same issue. Please help me for this issue. Please find the image below
. My snack bar code is Snackbar.make(coordinator,getString(R.string.validation_plz_enter_mandatory_flds, UtilConstants.ERROR_CODE_UI_2000),Snackbar.LENGTH_INDEFINITE).show();
- 196
- 1
- 14
-
And where exactly is the `SnackBar`, because I can't see it from the image? – Iulian Popescu Sep 28 '17 at 12:32
-
the black color is snackbar – Ganesh P Sep 28 '17 at 12:54
-
Can you add the code for the snackBar? – Iulian Popescu Sep 28 '17 at 12:55
-
i added my code – Ganesh P Sep 28 '17 at 13:00
-
share your xml file. that will better explain the situation. – Harminder Singh Sep 28 '17 at 13:18
-
Your Answer is : https://stackoverflow.com/questions/46469019/snackbar-is-not-showing-properly-if-the-keyboard-is-opened-in-android/52073565#52073565 – Prince Dholakiya Aug 29 '18 at 09:15
5 Answers
This is the Correct Solution of this problem: SnackBar show Above the SoftInput
(Keyboard) - (when Keyboard is Open)
<activity android:name=".YourActivity"
android:windowSoftInputMode="adjustResize"/>
tag into your activity tag of the manifest.
- 3,255
- 27
- 43
Have you initialized your snackbar like below code:
snackbar = Snackbar.make(findViewById(android.R.id.content), <Your message>, Snackbar.LENGTH_LONG);
or you have used your own layout??
Because if we use android's own UI element(android.R.id.content) it manages to show on valid UI of their own. You should first try this.
- 8,956
- 2
- 21
- 35
-
-
-
@AndroidGeek Thank you dude. Its very simple and elagent solution. It also solves my another one issue in displaying snackbar. – Jarin Rocks Jan 03 '19 at 11:14
Put this property in your Manifest file to your proper activity.
<activity android:name=".YourActivity"
android:windowSoftInputMode="adjustResize"/>
- 3,522
- 4
- 37
- 72
Just Hide the KeyBoard where you call your SnackBar using below code:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(parentLayout.getWindowToken(), 0); // parentLayout is your main layout of an activity
- 876
- 9
- 22
If your using CoordinatorLayout with AppBar and NestedLayout with EditText inside, it won't work.
This is a bug in support lib, reported here.
Similar question here.
You can use a workaround by wrapping the CoordinatorLayout with another Constraint/Relative Layout (PS I've not tried RealtiveLayout but works using ConstraintLayout) and use android:fitsSystemWindows="true".
with referenced to this answer.
- 13,092
- 8
- 34
- 45
