las*_*zlo 5 android android-button material-design material-components material-components-android
我想实现看起来像材料组件示例中的按钮形状

我已经尝试做的是为这样的按钮设置自定义样式
<style name="ButtonAddLeft" parent="Widget.MaterialComponents.Button.Icon">
<item name="backgroundTint">@color/secondary</item>
<item name="android:textColor">@color/primary</item>
<item name="shapeAppearance">@style/ButtonAddLeftShape</item>
</style>
<style name="ButtonAddLeftShape">
<item name="cornerFamilyTopLeft">cut</item>
<item name="cornerFamilyBottomLeft">cut</item>
<item name="cornerSize">12dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但这看起来不像示例中的那个,无论我如何设置cornerSize。
您需要将切角样式设置为主题。
<style name="RightCutButton" parent="ThemeOverlay.MaterialComponents.Light">
<item name="shapeAppearanceSmallComponent">@style/CornerCut</item>
</style>
<style name="CornerCut" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="cornerFamilyTopRight">cut</item>
<item name="cornerFamilyBottomRight">cut</item>
<item name="cornerSizeTopRight">18dp</item>
<item name="cornerSizeBottomRight">18dp</item>
</style>
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="shapeAppearanceSmallComponent">@style/CornerCut</item>
</style>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1515 次 |
| 最近记录: |