Android Custom Snackbar:无法删除边距 [英] Android Custom Snackbar: can't remove margins

查看:127
本文介绍了Android Custom Snackbar:无法删除边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建一个自定义的Snackbar不管是一个好主意,我都有一个自定义的Snackbar,我似乎无法摆脱空白.我已经尝试了几种方法,例如在代码和布局中进行调整,如下所示.似乎什么都没用.

Regardless of whether or not it is a good idea to create a custom Snackbar, I have a custom Snackbar and I can't seem to get rid of the margins. I've tried several things such as adjusting in code and in layout as shown below. Nothing seems to work.

我正在使用Yakiv在此处设置的方法:

I am using the approach laid out by Yakiv here:

final CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) snackBarView.getLayoutParams();
params.setMargins(0,0,0,0);

和其他方法,例如

android:layout_marginLeft="0dp"
android:layout_marginStart="0dp"
android:paddingLeft="0dp"
android:paddingStart="0dp" ...

小吃店:

我的布局文件:

<view
xmlns:android="http://schemas.android.com/apk/res/android"
class="android.support.design.internal.SnackbarContentLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/realBlack"
android:layout_marginLeft="0dp"
android:layout_marginStart="0dp"
android:paddingLeft="0dp"
android:paddingStart="0dp">

<TextView
    android:id="@+id/snackbar_text"
    android:layout_width="wrap_content"
    android:layout_height="60dp"
    android:layout_weight="1"
    android:paddingTop="@dimen/design_snackbar_padding_vertical"
    android:paddingBottom="@dimen/design_snackbar_padding_vertical"
    android:paddingLeft="@dimen/design_snackbar_padding_horizontal"
    android:paddingRight="@dimen/design_snackbar_padding_horizontal"
    android:textAppearance="@style/TextAppearance.Design.Snackbar.Message"
    android:maxLines="@integer/design_snackbar_text_max_lines"
    android:layout_gravity="center_vertical|left|start"
    android:ellipsize="end"
    android:textAlignment="viewStart"
    android:text="get some"/>

<Button
    android:id="@+id/snackbar_action"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/design_snackbar_extra_spacing_horizontal"
    android:layout_marginStart="@dimen/design_snackbar_extra_spacing_horizontal"
    android:layout_gravity="center_vertical|right|end"
    android:minWidth="48dp"
    android:visibility="gone"
    android:textColor="?attr/colorAccent"
    style="?attr/borderlessButtonStyle"/>
</view>

呼叫代码:

        _firmwareSnackbar = CustomSnackbar.make((ViewGroup) _rootView, Snackbar.LENGTH_INDEFINITE);

        _firmwareSnackbar.setText(_flipper.getContext().getString(R.string.settings_firmware_available));

        _firmwareSnackbar.setAction(_flipper.getContext().getString(R.string.settings_firmware_start), new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                _firmwareSnackbar.dismiss();
                _firmwareSnackbar = null;

            }
        });

        _firmwareSnackbar.show();

推荐答案

在dimens.xml中.

In dimens.xml.

使用此:

 <dimen name="design_snackbar_padding_horizontal">0dp</dimen>

但是请记住,这将应用于您应用程序中的所有小吃店.

But remember that this will get applied to all the snackbars in your application.

这篇关于Android Custom Snackbar:无法删除边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆