简体   繁体   English

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

[英]Android 4: Give buttons another style/appearance

I'd like to change the appearance of the default Android 4 buttons. 我想更改默认Android 4按钮的外观。 They look like that: 它们看起来像那样:

在此输入图像描述

I'd like them to be completely black, a white border, no rounded corners, that's all. 我希望它们完全是黑色,白色边框,没有圆角,这就是全部。 The blue hover effect is great, no change to that. 蓝色悬停效果很好,没有变化。 Unfortunately, there are a lot of parameters that button has. 不幸的是,按钮有很多参数。 Can I realize that with a single style.xml? 我能用单个style.xml来实现吗? Which are the interesting parameters? 哪些是有趣的参数?

Thank you very much. 非常感谢你。

Button Style: style.xml 按钮样式: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 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 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM