對不同API級別使用不同主題時,我會覆蓋每個主題的按鈕樣式。考慮下面的例子。
您的應用程序的API 14+的主題是一個派生自android:Theme.Holo.Light.DarkActionBar
的主題。
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</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">
<!-- API 21 theme customizations can go here. -->
</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按鈕樣式。 Widget.Button適用於所有API級別。
老式按鈕所有API級別 http://youtu.be/hKWUFgvw-Gs
styles.xml的文件夾中值看起來是這樣的:
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:buttonStyle">@style/Button</item>
</style>
<style name="Button" parent="@android:style/Widget.Button"></style>
每個按鈕樣式從的按鈕樣式派生其主題。
的按鈕具有材質動畫的文件夾中http://youtu.be/8Wp1TWjjha0
styles.xml 值-V21看起來是這樣的:
<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>
styles.xml的文件夾中值-V14外觀像這樣:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
</style>
<style name="BaseButton" parent="@android:style/Widget.Holo.Light.Button"></style>
</resources>
樣式。XML在文件夾值看起來是這樣的:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Light"></style>
<!-- Application theme. -->
<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>
Material Design for Android 5.0 (API level 21)
How to record your screen on Android 4.4.4
Video bitrates
是的,有按鈕樣式的項目。你確定你在你的應用程序中使用Theme.Black嗎? –
是的。但沒有buttonStyle,看到我的屏幕:http://s43.radikal.ru/i100/1302/f1/012f48561ebd.png –
沒有關係,eclipse沒有顯示它。它在那裏,嘗試輸入並運行你的應用程序。 –