我正在尝试在TAB中将Snakbar
设为MatchParent
。我所做的是:
Snackbar snackbar = Snackbar
.make(coordinatorLayout, mMessage, Snackbar.LENGTH_LONG);
View view = snackbar.getView();
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) view.getLayoutParams();
params.width = CoordinatorLayout.LayoutParams.MATCH_PARENT;
params.gravity = Gravity.CENTER | Gravity.BOTTOM;
view.setLayoutParams(params);
snackbar.show();
它增加了一个大的宽度而不是MatchParent
答案 0 :(得分:2)
对于仍在寻找答案的人:
Snackbar snackbar = Snackbar
.make(coordinatorLayout, mMessage, Snackbar.LENGTH_LONG);
View view = snackbar.getView();
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) view.getLayoutParams();+
params.gravity = Gravity.FILL_HORIZONTAL | Gravity.BOTTOM;
view.setLayoutParams(params);
snackbar.show();
'FILL_HORIZONTAL'为我做了诀窍。