1.创建一个Module命名为NumberAddSubView
2.创建自定义控件的布局文件number_add_sub_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/number_add_sub_view_selector"
android:gravity="center_vertical"
android:orientation="horizontal">
<Button
android:id="@+id/btn_sub"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:background="@drawable/btn_number_selector"
android:gravity="center"
android:text="-"
android:textColor="@android:color/black"
android:textSize="25sp" />
<TextView
android:layout_width="40dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="1"
android:textColor="@android:color/black"
android:textSize="20sp" />
<Button
android:id="@+id/btn_add"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:background="@drawable/btn_number_selector"
android:gravity="center"
android:text="+"
android:textColor="@android:color/black"
android:textSize="25sp" />
</LinearLayout>
3.布局中用到控件的选择器,整体布局的边框线number_add_sub_view_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<!--设置圆角-->
<corners android:radius="2dp"></corners>
<!--设置固定背景颜色-->
<solid android:color="#ffffff"></solid>
<!--设置边框颜色-->
<stroke android:color="#dddddd" android:width="1dp"></stroke>
</shape>
按钮控件的按下背景颜色选择器btn_number_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!--没按下状态-->
<item android:state_enabled="false">
<shape android:shape="rectangle">
<corners