If it posible could you tell me how can I do it? Else, please, tell me what can be used instead of Snackbar?
Asked
Active
Viewed 48 times
-1
-
I strongly recommend to make a quick Google search before posting your question here dude, but well.. Looking at Google's official doc, you can add actions to the Snackbar https://developer.android.com/training/snackbar/action.html – pamobo0609 Jan 24 '17 at 16:23
-
For adding layouts to your Snackbar, this post may be helpful: http://stackoverflow.com/a/33441214/4450805 – pamobo0609 Jan 24 '17 at 16:24
1 Answers
1
You can do it like this. BUT, I don't recommend to use this workaround. Usually you don't need to put custom layout in snackbar. Snackbar was developed as a unified way for all apps to notify about something.
CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.main_content);//coordimator layout where you use snackbar
snackbar = Snackbar.make(coordinatorLayout, "", Snackbar.LENGTH_INDEFINITE);
Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) snackbar.getView();//get the snackbar's view
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View snackView = inflater.inflate(R.layout.custom_layout, null);
snackView.setBackgroundColor(Color.WHITE);
layout.addView(snackView, 0);//add our custom view to snackbar
snackbar.show();

Aksenov Vladimir
- 677
- 1
- 6
- 16
-
1
-
I dont know xml method. But you can create you xml custom view and add this view by inflater. I showed this method above – Aksenov Vladimir Jan 24 '17 at 16:55