有圖有真相!絕不含糊!
還是挺美觀的吧?完全沒用圖檔資源
再來看一下代碼,主要是用xml實作的(代碼見傳送門: http://download.csdn.net/detail/u013127097/6996029)
右邊無邊框的button_style(分别有normal、selete狀态):
left_while_borde_rounded.xml
[html] view
plaincopyprint?
<?xmlversionxmlversion="1.0"encoding="utf-8"?>
<layer-listxmlns:androidlayer-listxmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<!-- 邊框顔色值 -->
<solidandroid:colorsolidandroid:color="#ffffff"/>
<!-- 左邊圓角值 -->
<corners
android:bottomleftradius="5dp"
android:topleftradius="5dp"/>
</shape>
</item>
<!-- 邊框size -->
<item
android:bottom="1.5dp"
android:left="1.5dp"
android:top="1.5dp">
<!-- 主體顔色值 -->
<solidandroid:colorsolidandroid:color="#e4a322"/>
</layer-list>
left_while_borde_rounded_focused.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#ffffff" />
android:topleftradius="5dp" />
左邊無邊框的button_style(分别有normal、selete狀态):
right_while_borde_rounded.xml
<!-- 右邊圓角值 -->
android:bottomrightradius="5dp"
android:toprightradius="5dp" />
android:right="1.5dp"
<solid android:color="#e4a322" />
right_while_borde_rounded_focused.xml
四邊都有邊框的button_style(分别有normal、selete狀态):
yellow_borde_rounded.xml
<!-- 連框顔色值 -->
android:topleftradius="5dp"
<!-- 主體背景顔色值 -->
yellow_borde_rounded_focused.xml
<span style="font-size:14px;color:#3366ff;"><?xml version="1.0" encoding="utf-8"?>
<!-- 圓角值 -->
</span>
再看activity_main.xml的布局,分别添加上面三種風格的按鈕
<span style="font-size:14px;color:#3366ff;"><linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical" >
<linearlayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#e4a322"
android:gravity="center"
android:orientation="horizontal" >
<button
android:id="@+id/swith_left"
android:layout_width="120dp"
android:layout_height="35dp"
android:background="@drawable/left_while_borde_rounded_focused"
android:text="job"
android:textcolor="#e4a322" >
</button>
android:id="@+id/swith_right"
android:background="@drawable/right_while_borde_rounded"
android:orientation="horizontal"
android:text="company"
android:textcolor="#ffffff" >
</linearlayout>
<button
android:id="@+id/submit_btn"
android:layout_width="120dp"
android:layout_height="35dp"
android:layout_gravity="center_horizontal"
android:layout_margintop="30dp"
android:background="@drawable/yellow_borde_rounded"
android:text="申請"
android:textcolor="#e4a322" >
</button>
</linearlayout></span>
最後在activity中添加按鈕事件
<span style="font-size:14px;color:#3366ff;">public class mainactivity extends activity {
boolean isselete;
@override
protected void oncreate(bundle savedinstancestate) {
super.oncreate(savedinstancestate);
setcontentview(r.layout.activity_main);
final button leftbtn = (button) findviewbyid(r.id.swith_left);
final button rightbtn = (button) findviewbyid(r.id.swith_right);
leftbtn.setonclicklistener(new onclicklistener() {
@override
public void onclick(view v) {
// todo auto-generated method stub
leftbtn.setbackgroundresource(r.drawable.left_while_borde_rounded_focused);
leftbtn.settextcolor(color.parsecolor("#e4a322"));
rightbtn.setbackgroundresource(r.drawable.right_while_borde_rounded);
rightbtn.settextcolor(color.parsecolor("#ffffff"));
}
});
rightbtn.setonclicklistener(new onclicklistener() {
leftbtn.setbackgroundresource(r.drawable.left_while_borde_rounded);
leftbtn.settextcolor(color.parsecolor("#ffffff"));
rightbtn.setbackgroundresource(r.drawable.right_while_borde_rounded_focused);
rightbtn.settextcolor(color.parsecolor("#e4a322"));
final button submitbtn = (button) findviewbyid(r.id.submit_btn);
submitbtn.setonclicklistener(new onclicklistener() {
if (isselete) {
submitbtn
.setbackgroundresource(r.drawable.yellow_borde_rounded);
submitbtn.settextcolor(color.parsecolor("#e4a322"));
} else {
.setbackgroundresource(r.drawable.yellow_borde_rounded_focused);
submitbtn.settextcolor(color.parsecolor("#ffffff"));
}
isselete = !isselete;
}
}</span>
代碼見傳送門: http://download.csdn.net/detail/u013127097/6996029