Android 4:给按钮另一种风格/外观

时间:2012-06-03 11:09:21

标签: java android

我想更改默认Android 4按钮的外观。它们看起来像那样:

enter image description here

我希望它们完全是黑色,白色边框,没有圆角,就是这样。蓝色悬停效果很好,没有变化。不幸的是,按钮有很多参数。我能用单个style.xml来实现吗?哪些是有趣的参数?

非常感谢。

1 个答案:

答案 0 :(得分:3)

按钮样式: style.xml

<style name="Button" parent="@android:style/Widget.Button">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textSize">@dimen/txt_size_medium</item>
    <item name="android:background">@drawable/btn</item>
    <item name="android:textColor">@drawable/btn_txt_selector</item>
    <item name="android:gravity">center</item>
</style>

btn.xml

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

    <item android:state_focused="true"><shape android:shape="rectangle">
            <gradient android:angle="270" android:centerColor="@color/btn_focused_center" android:endColor="@color/btn_focused_end" android:startColor="@color/btn_focused_start" />

            <corners android:radius="@dimen/radious_btn" />

            <padding android:bottom="@dimen/padding_bottom_btn" android:left="@dimen/padding_left_btn" android:right="@dimen/padding_right_btn" android:top="@dimen/padding_top_btn" />

            <stroke android:width="@dimen/border_width_btn" android:color="@color/btn_focused_border" />
        </shape></item>

    <item><shape android:shape="rectangle">
            <gradient android:angle="270" android:centerColor="@color/btn_normal_center" android:endColor="@color/btn_normal_end" android:startColor="@color/btn_normal_start" />

            <corners android:radius="@dimen/radious_btn" />

            <padding android:bottom="@dimen/padding_bottom_btn" android:left="@dimen/padding_left_btn" android:right="@dimen/padding_right_btn" android:top="@dimen/padding_top_btn" />

            <stroke android:width="@dimen/border_width_btn" android:color="@color/btn_normal_border" />
        </shape></item>

</selector>

btn_txt_selector.xml

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

    <item android:state_focused="true" android:color="@color/btn_txt_focused"></item>
    <item android:state_selected="true" android:color="@color/btn_txt_selected"></item>
    <item android:state_enabled="false" android:color="@color/btn_txt_disabled"></item>
    <item android:color="@color/btn_txt_normal"></item>

</selector>