【发布时间】:2020-07-18 03:47:41
【问题描述】:
我希望我的按钮有圆角,例如:
要在 android 中使用材质主题来实现这一点,请将:shapeAppearanceSmallComponent 设置为具有rounded 角。
但是设置shapeAppearanceSmallComponent 也会影响所有其他组件,例如EditText,所以现在它们也被舍入了。
所以我没有将其设置为shapeAppearanceSmallComponent,而是创建了一个shapeMaterialOverlay。将此叠加层设置为buttonStyle,并将主题中的此按钮样式设置为默认按钮样式。
它有效,但仅适用于默认按钮。如果我需要 TextButton 这样的:
<Button
...
style="@style/Widget.MaterialComponents.Button.TextButton"/>
TextButton 不会被环绕。因此,作为一种解决方法,我创建了从TextButton 扩展的MyTextButton 样式,并在那里设置了shapeOverlay。
所以现在如果我需要TextButton,我会这样做:
<Button
...
style="@style/Widget.MaterialComponents.Button.MyTextButton"/>
改为。
我必须为所有其他按钮类型执行此操作。我想知道这种方法是否正确,如果不正确,谁能指导我如何正确地做到这一点?
非常感谢。
【问题讨论】:
-
请使用谷歌文档
Shape Theming--- material.io/develop/android/theming/shape -
@DickensAS 文档实际上并未包含我上面介绍的场景。
-
它在标题
<item name="cornerSize">4dp</item>下Using shapeAppearance in the theme
标签: android material-design android-button material-components-android material-components