如何删除材料设计按钮中的额外填充或边距?

2024-04-19

我正在尝试创建一个附加到按钮上方的 TextView 的按钮,如下图所示。

上面的截图取自Note 4,操作系统版本为5.0.1。

下面是用于实现UI的代码。

布局/xyz.xml

    <Button
    android:layout_width="250dp"
    android:layout_height="50dp"
    android:theme="@style/myButton"
    android:text="Cancel"/>

值-v21/style.xml

    <style name="myButton" parent="@style/Base.Widget.AppCompat.Button">
    <item name="android:colorButtonNormal">#3578A9</item>
    <item name="android:inset">0dp</item>
    </style>

但如果我在 Nexus 4 OS 版本 5.1.1 中运行相同的代码,该按钮会占用所有 4 个边的边距,屏幕截图如下所示。

如果我删除“android:theme”并提供“android:background”,则 UI 看起来就像第一张图片。但它不会产生连锁反应。那么如何实现具有波纹效果的第一张图像的 UI。


安卓:insetBottom =“0dp”

<com.google.android.material.button.MaterialButton
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:text="Edit"
        app:cornerRadius="0dp"
        android:insetBottom="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何删除材料设计按钮中的额外填充或边距? 的相关文章

随机推荐