android shape 画边框,指定某一边
android要实现类似网页中的表格还带有边框的时候,这个边框还是不太好处理,有的时候四个边有的边有边线有的边线没有,处理方法如下:
shape之inset
<?xml version="1.0" encoding="utf-8"?> <!--画一个边线,四个边框只有上面没有边框--> <inset xmlns:android="http://schemas.android.com/apk/res/android" android:insetTop="-1dp"> <!--形状--> <shape android:shape="rectangle"> <!--填充颜色--> <solid android:color="@color/transparent"></solid> <!--描边--> <stroke android:width="1.0dp" android:color="@color/te6e6e6"></stroke> <!--paddint--> <padding android:left="0dp" android:right="0dp" android:top="0dp" android:bottom="0dp"></padding> <!--圆角--> <corners android:radius="0dp"/> </shape> </inset>
详情可以查看Android XML Drawable – Only Top & Bottom Border
shape之select 用于有多种状态的组件,如checkbox,radio,checkTextview
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/ac_order_check_press" android:state_checked="true"/> <item android:drawable="@drawable/ac_order_check_normal"/> </selector>
圆角非圆角空心非实心有边线的无边线的
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <!--形状--> <shape android:shape="rectangle"> <!--填充颜色--> <solid android:color="@color/t4ec68d"></solid> <!--描边--> <stroke android:width="0.8dp" android:color="@color/bbutton_title_edge"></stroke> <!--paddint--> <padding android:left="5dp" android:right="5dp" android:top="2dp" android:bottom="2dp"></padding> <!--圆角--> <corners android:radius="4dp"/> </shape> </item> </selector>
有多种状态的
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true"> <shape> <!--填充颜色--> <solid android:color="@color/bbutton_title_pressed"/> <!--描边--> <stroke android:width="1dp" android:color="@color/bbutton_title_edge"/> <padding android:left="5dp" android:right="5dp" android:top="2dp" android:bottom="2dp"></padding> <!--圆角--> <corners android:radius="4dp"/> </shape> </item> <item android:state_enabled="false"> <shape> <solid android:color="@color/bbutton_title_disabled"/> <stroke android:width="1dp" android:color="@color/bbutton_title_disabled_edge"/> <padding android:left="5dp" android:right="5dp" android:top="2dp" android:bottom="2dp"></padding> <corners android:radius="4dp"/> </shape> </item> <item android:state_checked="false"> <shape> <solid android:color="@color/bbutton_title_disabled"/> <stroke android:width="1dp" android:color="@color/bbutton_title_disabled_edge"/> <padding android:left="5dp" android:right="5dp" android:top="2dp" android:bottom="2dp"></padding> <corners android:radius="4dp"/> </shape> </item> <item> <shape android:shape="rectangle"> <solid android:color="@color/bbutton_title"></solid> <stroke android:width="0.8dp" android:color="@color/bbutton_title_edge"></stroke> <padding android:left="5dp" android:right="5dp" android:top="2dp" android:bottom="2dp"></padding> <corners android:radius="4dp"/> </shape> </item> </selector>
对应的color的颜色值
<resources> <?xml version="1.0" encoding="utf-8"?> <!--空心的蓝色边框的按钮--> <color name="bbutton_blue_title">#00ffffff</color> <color name="bbutton_blue_title_edge">#0081cc</color> <color name="bbutton_blue_title_pressed">#00ffffff</color> <color name="bbutton_blue_title_pressed_edge">#0081cc</color> <color name="bbutton_blue_title_disabled">#00ffffff</color> <color name="bbutton_blue_title_disabled_edge">#B4B4B4</color> </resource>