单位项目要求做一个分段式选择控制器,ios的有原生的,android感觉没有,于是看了下自己写了一个
效果图
参考资料
http://www.cnblogs.com/hebao0514/p/5649730.html
1.新建segment_text_color_selector.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="true"
android:color="#ffffff">
</item>
<item
android:color="#288455">
</item>
</selector>
(2)然后在res/drawable下新建segment_left_background.xml和segment_right_background.xml
这两个都是Segment-消息 和 Segment-电话 选中和没有选中两种状态对应的不同背景填充
segment_left_background.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape>
<stroke android:width="1dp" android:color="#ffffff" />
<solid android:color="#ffffff"/>
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="0dp"
android:topLeftRadius="5dp"
android:topRightRadius="0dp" />
</shape>
</item>
<item>
<shape>