【问题标题】:Attribute app:cornerRadius doen't work for the MaterialButton属性 app:cornerRadius 不适用于 MaterialButton
【发布时间】:2020-11-19 16:31:30
【问题描述】:

在屏幕的布局内,我正在尝试使用带有圆角的新材质组件实现 MaterialButton

<android.support.design.button.MaterialButton
        android:text="@string/login"
        android:id="@+id/btnEntrance"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginStart="104dp"
        style="@style/Widget.MaterialComponents.Button.UnelevatedButton" 
        android:layout_height="40dp"
        app:cornerRadius="8dp"/>

但是在预览屏幕上圆角是不可见的——这个属性不会对视图产生任何影响。谁能解释一下为什么?

【问题讨论】:

  • 您找到解决方案了吗?我也面临同样的问题。

标签: android material-components-android


【解决方案1】:
android:theme="@style/Theme.MaterialComponents"

将此行添加到您的材质按钮。

【讨论】:

    【解决方案2】:

    确保删除该属性:

    android:background="@color/white"
    

    如果需要使用背景,或者用 app:backgroundTint 替换它

    app:backgroundTint="@color/white"
    

    【讨论】:

      【解决方案3】:

      你的风格应该是这样的:

      <resources>
      
          <!-- Base application theme. -->
          <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
              <!-- Customize your theme here. -->
              <item name="colorPrimary">@color/colorPrimary</item>
              <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
              <item name="colorAccent">@color/colorAccent</item>
          </style>
      
      </resources>
      

      父主题应该来自Theme.MaterialComponents

      如果您想在预览中看到它,请单击并选择其他选项,如下图:

      【讨论】:

      • 这会形成一个cornerRadius
      • 我更改了 AppTheme 但它仍然不适合我。
      猜你喜欢
      • 2020-03-27
      • 2019-07-27
      • 2021-11-01
      • 2010-10-25
      • 2020-02-23
      • 1970-01-01
      • 1970-01-01
      • 2017-10-30
      • 2021-06-11
      相关资源
      最近更新 更多