使用xml属性 改变控件的样式和渐变色

来源:互联网 发布:nba历届得分王及数据 编辑:程序博客网 时间:2024/04/26 00:28

这里使用的是TextView作为测试控件  大家需要用什么控件都是大同小异的


效果图的展示:






下面是布局文件



 <EditText        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:hint="你好,这是一个测试"        android:background="@drawable/my_shape"         />    <EditText        android:layout_marginTop="30dp"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:hint="你好,这是一个测试"        android:background="@drawable/my_shape_02"        />    <EditText        android:layout_marginTop="30dp"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:hint="你好,这是一个测试"        android:background="@drawable/my_shape_03"        />

然后在res/drawable文件夹下建立样式表 这里起名是my_shape,my_shape_02,my_shape_03

选择的节点是Shape

附上代码  供大家参考

my_shape.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle">    <!--设置填充颜色-->    <solid android:color="#fff"/>    <!--设置内边距-->    <padding        android:top="7dp"        android:bottom="9dp"        android:left="3dp"        android:right="5dp"        />    <!--设置边框-->    <stroke android:width="3dip" android:color="#ff0"/></shape>


my_shape_02.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle">    <!--定义填充渐变颜色-->    <gradient        android:startColor="#ffff0000"        android:endColor="#80ff00ff"        android:angle="45"        />    <!--设置内填充-->    <padding        android:top="7dp"        android:bottom="7dp"        android:left="7dp"        android:right="7dp"        />    <!--设置圆角-->    <corners android:radius="8dp"/></shape>

my_shape_03.xml


<shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="oval">    <!--设置渐变颜色-->    <gradient        android:startColor="#ff0"        android:endColor="#00f"        android:angle="45"        android:type="sweep"        />    <padding        android:top="7dp"        android:bottom="7dp"        android:left="7dp"        android:right="7dp"        />    <!--设置圆角-->    <corners android:radius="8dp"/></shape>

大致就是这样 主要的是样式的设计 希望文章能帮到大家,谢谢



0 0
原创粉丝点击