Display Snackbar without CoordinatorLayout

前端 未结 4 1496
清歌不尽
清歌不尽 2021-02-06 00:20

I have Displayed Snackbar using CoordinatorLayout but in some layout i did\'t used CoordinatorLayout layout and i want to display snackbar but faced problem with it.

I h

4条回答
  •  北荒
    北荒 (楼主)
    2021-02-06 00:39

    As others suggest best solution to do this is via method mentioned before. I would add and option to show SnackBar with button to dismiss SnackBar. This comes useful when you'd like to give user time to read your message and then acknowledge your application that your user read your message.

       public void setSnackBar(View root, String textToDisplay) {
        Snackbar snackbar = Snackbar.make(root, textToDisplay, Snackbar.LENGTH_INDEFINITE);
        snackbar.setAction("OK", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                snackbar.dismiss();
                //your other action after user hit the "OK" button
            }
        });
        snackbar.show();
    

提交回复
热议问题