----------------------------------矩形或圆角类型(源代码下有属性解释)-----------------------------------------------------
一、shape 样式:(在drawable新建--》new--》Drawable resource file 并把原父级标签selector改为shape )
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#4ec5ff" />
<padding
android:bottom="12dp"
android:left="12dp"
android:right="12dp"
android:top="12dp" />
<corners android:radius="10dp" />
<stroke
android:width="2dp"
android:color="#ffffff"
android:dashGap="270dp" />
</shape>
二、style 样式:
<style name="rectangle">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">15sp</item>
<item name="android:textColor">#ffffff</item>
<item name="android:background">@drawable/buttonstyle</item>
</style>
三、Button控件调用style样式:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ly.blogtest.MainActivity">
<Button
android:id="@+id/button"
style="@style/rectangle"
android:text="@string/btn1" />
</RelativeLayout>
----------------------------------矩形或圆角类型-----------------------------------------------------
----------------------------------android:shape属性指定形状------------------------------
----------------------------------android:shape属性指定形状------------------------------
----------------------------------shape的属性标签-----------------------------------------
<shape>
<!-- 实心 -->
<solid android:color="#ff9d77"/>
<!-- 渐变 -->
<gradient
android:startColor="#ff8c00"
android:endColor="#FFFFFF"
android:angle="270" />
<!-- 描边 -->
<stroke
android:width="2dp"
android:color="#dcdcdc" />
<!-- 圆角 -->
<corners
android:radius="2dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
solid: 设置形状填充的颜色,只有android:color一个属性
padding: 设置内容与形状边界的内间距,可分别设置左右上下的距离
gradient: 设置形状的渐变颜色,可以是线性渐变、辐射渐变、扫描性渐变
corners: 设置圆角,只适用于rectangle类型,可分别设置四个角不同半径的圆角,当设置的圆角半径很大时,比如200dp,就可变成弧形边了
stroke: 设置描边,可描成实线或虚线。
----------------------------------shape的属性标签-----------------------------------------