-
先看下需求,下图是设置-开发者选项
里面的截图,里面有四种布局,不难看出他们有共同点,比如Title的样式是一样的,都有分割线等等。
-
鬣狗快速开发库中有一个自定义控件-MenuItemView。可以很好的实现上面的需求。
xmlns:item="http://schemas.android.com/apk/res-auto"
<com.knifestone.hyena.view.viewgroup.MenuItemView
android:layout_width="match_parent"
android:layout_height="50dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
item:iv_left_size="35dp"
item:iv_left_src="@mipmap/ic_launcher"
item:iv_right_src="@drawable/ic_chevron_right_black_24dp"
item:tv_title_color="#000"
item:tv_title_margin_left="10dp"
item:tv_title_text="鬣狗"
item:v_line_bottom_visibility="true" />
<attr name="tv_title_text" format="string" />
<attr name="tv_title_color" format="color" />
<attr name="tv_title_size" format="dimension" />
<attr name="tv_title_margin_left" format="dimension" />
<attr name="tv_title_margin_right" format="dimension" />
<attr name="tv_subtitle_text" format="string" />
<attr name="tv_subtitle_color" format="color" />
<attr name="tv_subtitle_size" format="dimension" />
<attr name="tv_subtitle_margin_left" format="dimension" />
<attr name="tv_subtitle_margin_right" format="dimension" />
<attr name="tv_subtitle_gravity" format="integer">
<enum name="left" value="0" />
<enum name="right" value="1" />
<enum name="bottom" value="2" />
</attr>
<attr name="iv_left_src" format="reference" />
<attr name="iv_left_size" format="dimension" />
<attr name="iv_left_margin_left" format="dimension" />
<attr name="iv_right_src" format="reference" />
<attr name="iv_right_size" format="dimension" />
<attr name="iv_right_margin_right" format="dimension" />
<attr name="switch_visibility" format="boolean" />
<attr name="switch_checked" format="boolean" />
<attr name="v_line_color" format="color" />
<attr name="v_line_top_visibility" format="boolean" />
<attr name="v_line_top_margin_left" format="dimension" />
<attr name="v_line_top_margin_right" format="dimension" />
<attr name="v_line_top_margin_height" format="dimension" />
<attr name="v_line_bottom_visibility" format="boolean" />
<attr name="v_line_bottom_margin_left" format="dimension" />
<attr name="v_line_bottom_margin_right" format="dimension" />
<attr name="v_line_bottom_margin_height" format="dimension" />
setTitle | 设置标题
setSubTitle | 设置副标题
setOnCheckedChangeListener | 设置Switch监听
setChecked | 设置Switch
getChecked | 获得Switch