思路:主界面只有一张背景图片,两个按钮,当按钮按下的时候,按钮的颜色会发生相应的变化,按下的分成了三个状态,default,pressed和selected。
在Activity中,对button进行了监听,并对监听事件进行了处理。处理的方式是弹出dialog对话框进行数据交互。main.xml文件:
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/wel"
android:orientation="vertical"
android:scrollbarStyle="insideOverlay" >
android:id="@+id/welView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:textColor="#f7f6fc" />
android:id="@+id/button3"
android:layout_width="80dip"
android:layout_height="30dip"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="44dp"
android:layout_marginLeft="56dp"
android:background="@drawable/bg_alibuybutton"
android:text="@string/buttonone"
android:textColor="#fcfcfd"
android:textSize="20sp" />
android:id="@+id/button2"
android:layout_width="80dip"
android:layout_height="30dip"
android:layout_alignBaseline="@+id/button3"
android:layout_alignBottom="@+id/button3"
android:layout_alignParentRight="true"
android:layout_marginRight="57dp"
android:background="@drawable/bg_alibuybutton"
android:text="@string/buttontwo"
android:textColor="#fcfcfd"
android:textSize="20sp" />
bg_alibuybutton.xml文件:<?xml version="1.0" encoding="UTF-8"?>
android:drawable="@drawable/bg_alibuybutton_pressed" />
android:drawable="@drawable/bg_alibuybutton_selected" />
bg_alibuybutton_default.xml文件:
android:topLeftRadius="5dip"
android:topRightRadius="5dip"
android:bottomLeftRadius="5dip"
android:bottomRightRadius="5dip" />
android:startColor="#7e71c9" android:endColor="#614ae9"
android:type="linear" android:angle="90"
android:centerX="0.5" android:centerY="0.5" />
android:topLeftRadius="5dip"
android:topRightRadius="5dip"
android:bottomLeftRadius="5dip"
android:bottomRightRadius="5dip" />
android:topLeftRadius="5dip"
android:topRightRadius="5dip"
android:bottomLeftRadius="5dip"
android:bottomRightRadius="5dip" />
android:startColor="#7e71c9" android:endColor="#614ae9"
android:type="linear" android:angle="90"
android:centerX="0.5" android:centerY="0.5" />
android:topLeftRadius="5dip"
android:topRightRadius="5dip"
android:bottomLeftRadius="5dip"
android:bottomRightRadius="5dip" />
bg_alibuybutton_selected.xml文件:<?xml version="1.0" encoding="utf-8"?>
android:topLeftRadius="5dip"
android:topRightRadius="5dip"
android:bottomLeftRadius="5dip"
android:bottomRightRadius="5dip" />
android:startColor="#FFEC7600" android:endColor="#FFFED69E"
android:type="linear" android:angle="90"
android:centerX="0.5" android:centerY="0.5" />
android:topLeftRadius="5dip"
android:topRightRadius="5dip"
android:bottomLeftRadius="5dip"
android:bottomRightRadius="5dip" />
bg_alibuybutton_pressed.xml文件
android:topLeftRadius="5dip"
android:topRightRadius="5dip"
android:bottomLeftRadius="5dip"
android:bottomRightRadius="5dip" />
android:startColor="#7e71c9" android:endColor="#614ae9"
android:type="linear" android:angle="90"
android:centerX="0.5" android:centerY="0.5" />
android:topLeftRadius="5dip"
android:topRightRadius="5dip"
android:bottomLeftRadius="5dip"
android:bottomRightRadius="5dip" />