初学Android,使用Drawable资源之使用ShapeDrawable资源(十五)
16lz
2021-01-26
ShapeDrawable比较简单,用来定义一个基本几何图形,XML的根元素是<shape.../>
下面定义三个shape资源
my_shape_1.xml
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <!-- 设置填充颜色 --> <solid android:color="#fff"/> <!-- 设置四周的内边距 --> <padding android:left="7dp" android:top="7dp" android:right="7dp" android:bottom="7dp"/> <!-- 设置边框 --> <stroke android:width="3dip" android:color="#ff0"/></shape>
my_shape_2.xml
<?xml version="1.0" encoding="utf-8"?><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:left="7dp" android:top="7dp" android:right="7dp" android:bottom="7dp"/> <!-- 设置圆角矩形 --> <corners android:radius="8dp"/></shape>
my_shape_3.xml
<?xml version="1.0" encoding="utf-8"?><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:left="7dp" android:top="7dp" android:right="7dp" android:bottom="7dp"/> <!-- 设置圆角矩形 --> <padding android:left="7dp" android:top="7dp" android:right="7dp" android:bottom="7dp"/> <!-- 设置圆角矩形 --> <corners android:radius="8dp"/></shape>
主界面的三个EditBox的背景分别使用上前面定义的三个shape
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <EditText android:id="@+id/editText1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:ems="10" android:background="@drawable/my_shape_1"> <requestFocus /> </EditText> <EditText android:id="@+id/editText2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:ems="10" android:background="@drawable/my_shape_2"/> <EditText android:id="@+id/editText3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:ems="10" android:background="@drawable/my_shape_3"/></LinearLayout>
运行效果如下
这样的效果看起来怪怪的,文本框的背景被弄的乱七八糟了
更多相关文章
- Android(安卓)自定义Dialog、IOS风格;
- Android使用wheelView实现简单类似ios PickerView选择器效果
- android 如何隐藏4.0以上系统下面的3按个虚拟按键?
- Android之DatePicker和TimePicker实现以及自定义大小
- android 输入框 XML 设置于代码设置异同
- Android(安卓)抽屉模型实现(Drawer),AndroidX and NavigationView
- Android(安卓)使用HTTPClient调用Web请求(查询手机号码区域)
- Android(安卓)权限表
- android 补间动画TranslateAnimation