android - 如何删除 Material 设计按钮中的额外填充或边距?

标签 android android-layout

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

enter image description here

以上截图来自Note 4,操作系统版本为5.0.1。

下面是实现UI的代码。

布局/xyz.xml

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

values-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>

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

enter image description here

如果我删除“android:theme”并提供“android:background”,UI 看起来就像第一张图片。但它不会产生链式 react 。那么如何将 UI 实现为具有涟漪效果的第一张图片。

最佳答案

android: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" />

关于android - 如何删除 Material 设计按钮中的额外填充或边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34989961/

相关文章:

Android ImageButton 选择器 - 每个按钮一个 xml?

android - 如何在android中的每个 View 顶部显示图像(例如,像市场上的碎屏应用程序)

android - picasso 什么时候刷新图像缓存

android - AlertDialog EditText 不显示软键盘

android - 工具栏在布局中不可见

android - 错误 :Execution failed for task ':app:transformClassesWithPreJackRuntimeLibrariesForDebug'

html - 我可以在 View 之外启动 webview,抓取 html 并通过它发布表单吗?

Android普通按钮变透明

android - 无论如何以编程方式动画线性布局的布局权重属性

android - getActionBar() 总是返回 null