0

I am using SnackBar for single line message for related operation.

Snackbar snackBar;
public void showSnackBar(View view){
    snackBar = Snackbar.make(view, "Searching for GPS", Snackbar.LENGTH_INDEFINITE);
    snackBar.show();
}

In the method isGPSEnabled , i use the method showSnackBar

if(Helper.isGPSEnabled(this)){
            showSnackBar(findViewById(android.R.id.content));
}

But I got this,

this

Why SnackBar allow some space from bottom bar ?

Edit

The layout file :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/content"
    android:orientation="vertical"
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"
    android:background="@android:drawable/edit_text"
    android:divider="@android:drawable/divider_horizontal_textfield"
    android:addStatesFromChildren="true">

<LinearLayout android:id="@+id/container"
    android:orientation="vertical"
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"
    android:paddingEnd="0dip"
/>

<AutoCompleteTextView android:id="@+id/edit"
    android:completionThreshold="1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:layout_gravity="center_vertical"
/>   
</LinearLayout>
Satan Pandeya
  • 3,747
  • 4
  • 27
  • 53
  • I do not know the reason why, but maybe `snackbar.getView().setTranslationY(25f);` solves this issue. From @DennyWeinberg https://stackoverflow.com/a/61599387/4300670 – Aliton Oliveira May 30 '20 at 00:05

2 Answers2

0

Please check android.R.id.content view in your layout file. SnackBar will be shown at the bottom of this view if it is FrameLayout. If you have added padding try removing it.

Can help you better, if you share the layout code.

Trinimon
  • 13,839
  • 9
  • 44
  • 60
Sravan
  • 371
  • 1
  • 8
  • As per your code app should crash. Because `android.R.id.content` is different from `android:id="@+id/content"`. Try changing `findViewById(R.id.content)` or `android:id="@android:id/content"` – Sravan Sep 28 '16 at 02:08
  • How do i need to call that `showSnackBar` method in `isGPSEnabled` method ? – Satan Pandeya Sep 28 '16 at 02:50
0

change 'content' Linear layout_height = "match_parent"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/content"
    android:orientation="vertical"
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:background="@android:drawable/edit_text"
    android:divider="@android:drawable/divider_horizontal_textfield"
    android:addStatesFromChildren="true">

add answer. try this.

in xml linear id change

android:id="@+id/content" to android:id="@+id/parentLinear"

and code

LinearLayout linear = (LinearLayout)findViewById(R.id.parentLinear);
Snackbar.make(linear, "Searching for GPS", Snackbar.LENGTH_INDEFINITE).show();
Andromer
  • 123
  • 2
  • 12