材质按钮上的圆角 [英] Rounded corners on material button
问题描述
我正在遵循诸如此之类的问题的提示,以创建按钮样式就像在Material Design上建议的那样.
I'm following the tips from questions like this to create a button style like suggested on Material Design.
但是,我需要更改转角半径,但无法通过继承Widget.AppCompat.Button.Colored
样式并设置radius参数来更改.
However, I need to change the corner radius and haven't been able to do so by inheriting Widget.AppCompat.Button.Colored
style and setting the radius parameter.
我如何具有相同的样式却带有圆角?
How can I have the same style but with rounded corners?
推荐答案
更新:
下面的Gabriele Mariotti的答案现在更好了.
Update:
Answer by Gabriele Mariotti below is now better.
您需要继承该样式.
添加到您的styles.xml中:
Add into your styles.xml:
<style name="AppTheme.RoundedCornerMaterialButton" parent="Widget.AppCompat.Button.Colored">
<item name="android:background">@drawable/rounded_shape</item>
</style>
添加文件drawable/rounded_shape.xml:
Add file drawable/rounded_shape.xml:
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:color="@color/colorAccent" >
</solid>
<corners
android:radius="11dp" >
</corners>
</shape>
最后是您的布局:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test Text"
style="@style/AppTheme.RoundedCornerMaterialButton"/>
更新了答案,以使用主题的颜色而不是硬编码.
updated answer to use theme's color rather than hardcoded one.
这篇关于材质按钮上的圆角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!