3

buttonStyleアイテム名 がないため、これは機能しません。しかありませんbutton

私の例:

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="AppTheme" parent="@android:style/Theme.Black">
        <item name="android:button">@style/ThemeButton</item>
    </style>

    <style name="ThemeButton" parent="@android:style/Widget.Button">
        <item name="android:background">@drawable/button</item>
    </style>

</resources>

しかし、これもうまくいきません。

4

1 に答える 1

6

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そのため、アプリケーションでから派生すると、Google のエンジニアが提供したとWidget.Buttonのカスタマイズが失われます。Widget.Material.Light.ButtonWidget.Holo.Light.Button

これを示すためにいくつかの例を記録しました。

Android ボタン スタイル。すべての API レベルの Widget.Button。

すべての 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

フォルダー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>

フォルダーの値の styles.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>

Android 5.0 のマテリアル デザイン (API レベル 21)

Android 4.4.4 で画面を録画する方法

ビデオのビットレート

于 2014-10-29T08:43:23.530 に答える