如何将样式应用于Android应用程序中的所有按钮?

Max*_*tar 2 android styles button

不起作用,因为没有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>
Run Code Online (Sandbox Code Playgroud)

但这也不起作用.

Mak*_*iev 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>
Run Code Online (Sandbox Code Playgroud)

android:Theme.Holo.Light.DarkActionBar没有自己的buttonStyle,但它的父母呢Theme.Holo.Light.按钮样式如下:

<item name="buttonStyle">@style/Widget.Holo.Light.Button</item>
Run Code Online (Sandbox Code Playgroud)

但是,API 21的应用程序主题源于 android:Theme.Material.Light.DarkActionBar

<style name="AppBaseTheme" parent="android:Theme.Material.Light.DarkActionBar">
    <!-- API 21 theme customizations can go here. -->
</style>
Run Code Online (Sandbox Code Playgroud)

按钮样式android:Theme.Material.Light如下:

<item name="buttonStyle">@style/Widget.Material.Light.Button</item>
Run Code Online (Sandbox Code Playgroud)

Widget.Button是的祖父Widget.Holo.Light.ButtonWidget.Material.Light.Button我在上面提到.所以,如果你得到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>
Run Code Online (Sandbox Code Playgroud)

每个按钮样式都源自其主题的按钮样式.

该按钮具有材质动画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>
Run Code Online (Sandbox Code Playgroud)

文件夹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>
Run Code Online (Sandbox Code Playgroud)

文件夹中的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>
Run Code Online (Sandbox Code Playgroud)

Android 5.0的Material Design(API级别21)

如何在Android 4.4.4上录制您的屏幕

视频比特率