当使用不同的API级别为不同的主题时,我会覆盖每个主题的按钮样式。考虑以下示例。
您的应用程序适用于API 14+的主题是从android:Theme.Holo.Light.DarkActionBar
派生的主题。
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!
</style>
android:Theme.Holo.Light.DarkActionBar
没有自己的buttonStyle
,但它的父级Theme.Holo.Light
有。按钮样式如下:
<item name="buttonStyle">@style/Widget.Holo.Light.Button</item>
但是你的应用程序在API 21及以上版本中的主题派生自android:Theme.Material.Light.DarkActionBar
<style name="AppBaseTheme" parent="android:Theme.Material.Light.DarkActionBar">
<!
</style>
android:Theme.Material.Light
的按钮风格如下:
<item name="buttonStyle">@style/Widget.Material.Light.Button</item>
Widget.Button
是我之前提到的
Widget.Holo.Light.Button
和
Widget.Material.Light.Button
的祖先。因此,如果您在应用程序中派生自
Widget.Button
,您将失去Google工程师为
Widget.Material.Light.Button
和
Widget.Holo.Light.Button
提供的自定义功能。
我录制了一些示例以说明这一点。
Android按钮样式。所有API级别使用Widget.Button。
所有API级别使用的老式按钮
http://youtu.be/hKWUFgvw-Gs
values文件夹中的styles.xml如下所示:
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<!
<style name="AppTheme" parent="AppBaseTheme">
<!
<item name="android:buttonStyle">@style/Button</item>
</style>
<style name="Button" parent="@android:style/Widget.Button"></style>
每一个按钮样式都来自于它所属的主题中的按钮样式。
该按钮拥有Material动画,详情请参见http://youtu.be/8Wp1TWjjha0
values-v21文件夹中的styles.xml文件如下:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Material.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
<style name="BaseButton" parent="@android:style/Widget.Material.Light.Button"></style>
</resources>
位于文件夹values-v14中的styles.xml如下:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
</style>
<style name="BaseButton" parent="@android:style/Widget.Holo.Light.Button"></style>
</resources>
文件夹中的values中的styles.xml如下所示:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Light"></style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:buttonStyle">@style/Button</item>
</style>
<style name="Button" parent="@style/BaseButton">
<item name="android:text">Lorem Ipsum</item>
</style>
</resources>
安卓5.0(API 21)的Material Design
如何在安卓4.4.4上录制屏幕
视频比特率