Android中所有按钮的通用主题

时间:2012-03-30 13:11:33

标签: java android xml themes

我希望为整个应用程序中的所有活动中的所有按钮创建一个共同主题。我想只为焦点和默认放置2个图像......我想在xml中做所有这些我怎么能这样做?

3 个答案:

答案 0 :(得分:1)

    <?xml version="1.0" encoding="utf-8"?>

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

        <item
            android:state_focused="true"
            android:state_pressed="false"
            android:drawable="@drawable/btn_focused" />

        <item
            android:state_focused="true"
            android:state_pressed="true"
            android:drawable="@drawable/btn_pressed_focused" />

        <item
            android:state_focused="false"
            android:state_pressed="true"
            android:drawable="@drawable/btn_pressed" />

        <item android:color="#ffffff" />

    </selector>

答案 1 :(得分:0)

最简单的方法是使用主题作为按钮。阅读:Styles and Themes

答案 2 :(得分:0)

为您的按钮创建样式,然后使用父

创建样式(这是一个主题)
parent="android:Theme.something"

的值为

<item name="android:buttonStyle">@style/my_button_style</item>

然后在清单中,应用程序和activity元素中都有一个theme属性。