【问题标题】:MaterialButton wider than it should beMaterialButton 比应有的宽度更宽
【发布时间】:2020-10-29 19:06:59
【问题描述】:

在实现MaterialButton 之后,由于某种原因,它的宽度似乎没有换行到里面的文本,从而在右侧留下了额外的空间。 MaterialButton 是否需要在 ConstraintLayout 中才能正常工作?还是我的代码中有什么不正确的地方?

按钮布局

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.button.MaterialButton
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/myBtn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="start|center_vertical"
    android:padding="12dp"
    android:layout_margin="12dp"
    style="@style/Widget.MaterialComponents.Button.OutlinedButton" />

【问题讨论】:

    标签: android xml android-button material-components-android


    【解决方案1】:

    MaterialButton 使用的样式在其层次结构的深处继承自 Base.Widget.AppCompat.Button,它定义了此属性:

    <item name="android:minWidth">88dip</item>
    

    你可以用你自己的风格/主题或直接在你的&lt;Button&gt;标签上覆盖它:

    android:minWidth="1dp"
    

    您可以通过查看Widget.MaterialComponents.Button 样式的快速文档来了解这一点(滚动到底部):

    【讨论】:

      猜你喜欢
      • 2014-08-26
      • 2021-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-30
      相关资源
      最近更新 更多