【问题标题】:Android Styling: Setting border to 0sp does not remove border radius of Material ButtonAndroid 样式:将边框设置为 0sp 不会删除 Material Button 的边框半径
【发布时间】:2019-11-22 22:38:52
【问题描述】:

我正在尝试设置一个按钮的样式,使其没有边框半径。我尝试将radius 属性设置为0sp,但这没有奏效。下面是我的代码和生成的按钮的屏幕截图,它仍然有圆角。

<com.google.android.material.button.MaterialButton
        android:id="@+id/material_text_button"
        style="@style/Widget.MaterialComponents.Button.OutlinedButton"
        android:textAppearance="@style/Widget.MaterialComponents.Button.OutlinedButton"
        android:layout_marginTop="11sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:radius="0sp"
        android:text="#1 Lorem Ipsum"
        android:textSize="16sp"/>

【问题讨论】:

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


    【解决方案1】:

    对于圆角半径,使用 app:cornerRadius 属性:

    <com.google.android.material.button.MaterialButton
        app:cornerRadius="0dp"
        ../>
    

    概述/填充结果:

    关于您的布局,请在这些维度中使用 dp 而不是 sp

        android:layout_marginTop="11sp" //dp
        android:radius="0sp"  //dp and app:cornerRadius
    

    这种风格@style/Widget.MaterialComponents.Button.OutlinedButton不应该用在android:textAppearance中。

    【讨论】:

      猜你喜欢
      • 2018-05-07
      • 2016-01-13
      • 1970-01-01
      • 2018-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-02
      相关资源
      最近更新 更多