如何在Tab中制作Snackbar MatchParent?

时间:2016-05-26 13:46:25

标签: android android-layout android-snackbar

我正在尝试在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

1 个答案:

答案 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'为我做了诀窍。