Android-资源

xiaoxiao2021-02-28  115

一、什么是资源?

所谓资源都是指在res文件夹下的xml文件,每一种类型的xml文件都对应了一种资源

二、外形资源(shape)

1、shape资源用于定义一个基本的几个图形(矩形,圆形,线条等)

2、属性android:shape    取值(rectangle 矩形,oval椭圆,line直线,ring圆环)

3、子节点

3.1  <corners/>定义几何图形四个角度的弧度

                    android:radius  设置四个角的弧度

    android:xxxradius  设置某一个角的弧度

3.2<gradient/>定义使用渐变颜色填充

android:startColor  开始颜色

android:centerColor  中间颜色

android:endColor结束颜色

android:angle 方向角度(取值必须是45的整倍数)(0从左到右,90从上到下)

android:type  渐变类型(取值:liear 线性渐变,radial径向渐变)(一定要指定android:gradientRadius属性)

3.3<padding/>定义几何形状的内边距

3.4<size/>定义几何形状的大小

3.5<solid/>定义使用单种颜色填充 android:color

3.6<stroke/>定义几何形状的边框

                ①android:with  边框的高度

②android:color 边框的颜色

③android:dashWidth 虚线的宽度

④android:dashGap 虚线的间距

实例:

代码:

布局文件:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <EditText android:layout_width="match_parent" android:layout_height="50dp" android:paddingLeft="100dp" android:focusable="true" android:focusableInTouchMode="true" android:clickable="true" android:background="@drawable/et_selector" android:hint="请输入用户名" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="6dp" android:gravity="center" android:text="用户名:" android:drawableLeft="@drawable/icon_user" /> </FrameLayout> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:focusableInTouchMode="true" android:clickable="true" android:focusable="true" android:background="@drawable/et_selector" android:hint="请输入密码" > <EditText android:layout_width="wrap_content" android:layout_height="50dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="6dp" android:gravity="center" android:text=" 密码:" android:drawableLeft="@drawable/icon_user" /> </FrameLayout> </LinearLayout> 选择器:

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:drawable="@drawable/et_shape1"> </item> <item android:state_focused="false" android:drawable="@drawable/et_shape"> </item> </selector> 状态一:

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <!--设置背景颜色--> <solid android:color="#ff0000"> </solid> <!--设置边框--> <stroke android:width="2dp" android:color="#ff00ea" ></stroke> <!--设置边框弧度--> <corners android:topLeftRadius="10dp" android:bottomLeftRadius="10dp" android:topRightRadius="10dp" android:bottomRightRadius="10dp" > </corners> </shape>

状态二:

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <!--设置背景颜色--> <solid android:color="#00ffee"></solid> <!--设置边框--> <stroke android:width="2dp" android:color="#00ff00"></stroke> <!--设置边框弧度--> <corners android:topLeftRadius="10dp" android:bottomLeftRadius="10dp" android:topRightRadius="10dp" android:bottomRightRadius="10dp" ></corners> </shape>

三、尺寸资源(Dimension)

           1、dimen标签用于定义尺寸资源

   2、<dimen name=""><dimen>

四、颜色资源(Color)

1、color标签用于定义尺寸资源

2、<color name=""></color>

转载请注明原文地址: https://www.6miu.com/read-66043.html

最新回复(0)