如何应用android首次启动时使用的默认“蓝色按钮”样式?

时间:2013-11-22 09:31:04

标签: android button colors

即,如何应用this按钮样式?我指的是右下角的蓝色按钮。

4 个答案:

答案 0 :(得分:2)

在res文件夹中创建一个drawable文件夹,然后创建XML文件并将其命名为button_background 在XML文件中,您将定义按钮的形状,例如颜色,角落,笔触和填充,您可以在此处执行所有操作。以下代码与按钮类似:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
    <shape>
        <solid
            android:color="#56b7cc" />
        <stroke
            android:width="1dp"
            android:color="#70daf1" />
        <corners
            android:radius="3dp" />
        <padding
            android:left="10dp"
            android:top="10dp"
            android:right="10dp"
            android:bottom="10dp" />
    </shape>
</item>
<item>
    <shape>
        <gradient
            android:startColor="#68c8dd"
            android:endColor="#70daf1"
            android:angle="270" />
        <stroke
            android:width="1dp"
            android:color="#70daf1" />
        <corners
            android:radius="4dp" />
        <padding
            android:left="10dp"
            android:top="10dp"
            android:right="10dp"
            android:bottom="10dp" />
    </shape>
</item>
</selector>

然后在你的布局中给出按钮:

<Button
    android:id="@+id/Button1"
    android:layout_width="50dip"
    android:layout_height="40dip"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_marginBottom="107dp"
    android:background="@drawable/button_background"
    android:textColor="#ffffff"
    android:text="ok" />

我制作了固定的宽度和高度,因此看起来像是图片,最重要的属性是

android:background="@drawable/button_background"

您可以通过更改颜色来修改它,填充更多地了解它here。希望这就是你要找的东西

答案 1 :(得分:1)

其android ShowcaseView功能。您可以参考here

答案 2 :(得分:1)

如果您只想要按钮样式,则需要创建自己的按钮样式并基于,例如:

九片图片

using nine-patch image as Background of Button androidButton with 9-patch image background doesn't stretch correctly),

或基于形状How to create custom button in Android using XML Styles

答案 3 :(得分:1)

style.xml

<style name="Button.Blue" parent="android:Widget.Holo.Light.Button">
    <item name="android:background">@drawable/xbg_blue_button</item>
    <item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
    <item name="android:textColor">@android:color/white</item>
    <item name="android:textStyle">bold</item>
</style>

xbg_blue_button.xml

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

<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<item android:state_focused="true"  android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/btn_default_disabled_holo_light" />
<item android:state_focused="true"  android:state_enabled="false"                              android:drawable="@drawable/btn_default_disabled_focused_holo_light" />
<item android:state_focused="true"                                android:state_pressed="true" android:drawable="@drawable/btn_default_pressed_holo_light" />
<item android:state_focused="false"                               android:state_pressed="true" android:drawable="@drawable/btn_default_normal_holo_light" />
<item android:state_focused="true"                                                             android:drawable="@drawable/btn_default_focused_holo_light" />
<item                                                                                          android:drawable="@drawable/btn_default_normal_holo_light" />

绘项目: https://dl.dropboxusercontent.com/u/54394631/buttons.rar