Snackbar is not dismissing on swipe

后端 未结 4 1914
没有蜡笔的小新
没有蜡笔的小新 2021-02-19 02:39

i have a snackbar in my appcompat activity. It has a button OK which dismiss the snackbar.It is working perfact. but i can\'t dismiss the snackbar on swipe(left to right).

4条回答
  •  一整个雨季
    2021-02-19 03:08

    As a reference to Ashwani Kumars answer. I saw Intimate asked if there is a way to implement this with LinearLayout. Well simple wrap your original LinearLayout with a CoordinatorLayout with match_parent in android:layout_height and android:layout_width attributes.

    this will keep your original arrangement and still make sure the Snackbar is swipable.

    Snackbar will now look like this:

    For fragments -

    Snackbar.make(getView(), "Error Message", Snackbar.LENGTH_INDEFINITE);
    

    For activities -

    Snackbar.make(this.findViewById(android.R.id.content), "Error Message",  Snackbar.LENGTH_INDEFINITE);
    

    Assuming you wraped your whole layout with CoordinatorLayout and this is the root layout.

提交回复
热议问题