1

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

在此处输入图像描述

我希望它们完全是黑色的,有白色的边框,没有圆角,仅此而已。蓝色悬停效果很棒,没有改变。不幸的是,按钮有很多参数。我可以用一个 style.xml 来实现吗?哪些是有趣的参数?

非常感谢你。

4

1 回答 1

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>
于 2012-06-03T11:38:41.970 回答