Jef*_*xon 12 android android-appcompat android-ui android-theme
我正在使用AppCompat主题,我想在我的按钮上设置minHeight属性:
<style name="Theme.MyTheme" parent="Theme.AppCompat">
<item name="android:buttonStyle">@style/MyButtonStyle</item>
</style>
<style name="MyButtonStyle" parent="...?">
<item name="android:minHeight">60dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但是,没有Widget.AppCompat.Button样式可以设置为父项MyButtonStyle.如果我使用android:Widget.Button,那么我的所有按钮看起来都像旧的蹩脚风格.我尝试了各种其他AppCompat主题TextAppearance.AppCompat.Button,但它们不起作用.
省略按钮样式的父主题也会导致按钮无法正确设置样式.
如何自定义默认值Theme.AppCompat buttonStyle?
您可以在 API 14+(在)和API 21+(在 )上进行Base.MyButtonStyle扩展。此样式将根据设备系统版本而变化。将您的平台特定修改放在这里。android:Widget.Holo.Buttonres/values-v14/styles.xmlandroid:Widget.Material.Buttonres/values-v21/styles.xml
然后MyButtonStyle扩展Base.MyButtonStyle并定义android:minHeighthere(in res/values/styles.xml)。这将适用于所有平台。
然后您的按钮就可以使用 style MyButtonStyle。
此示例假设您的最低 SDK 为 14。
是的,没有 appcompat-v7 按钮样式(好吧,至少现在还没有)。
编辑
这假设您可以在早于 Lollipop 的平台上使用 Holo 按钮。感觉不引人注目,如果你能做到没有涟漪,那就应该没问题。如果你想要涟漪,我建议你谷歌搜索第三方棒棒糖按钮库。
在 styles.xml 中使用 AppCompat +22 自定义按钮样式
<style name="Button.Tinted" parent="Widget.AppCompat.Button">
<item name="colorButtonNormal">YOUR_TINT_COLOR</item>
<item name="colorControlHighlight">@color/colorAccent</item>
<item name="android:textColor">@android:color/white</item> </style>
Run Code Online (Sandbox Code Playgroud)
在你的layout.xml中
<Button
android:id="@+id/but_next"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/but_continue"
android:theme="@style/Button.Tinted" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16311 次 |
| 最近记录: |