您的位置:首页 > 移动开发 > Android开发

【Android】安卓开发实战之自定义EditText输入框形状颜色

2017-02-20 23:51 483 查看
下面来看一下实现方法:

1、先在drawable文件夹下创建一个myedittext.xml文件,文件代码如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!--solid里是背景的填充颜色,transparent是透明-->
<solid android:color="@android:color/transparent"/>
<!--
corners里的属性,是四个边角拐角的大小
topLeftRadius:左上角
topRightRadius:右上角
bottomRightRadius:右下角
bottomLeftRadius:左下角
-->
<corners
android:topLeftRadius="100dp"
android:topRightRadius="10dp"
android:bottomRightRadius="100dp"
android:bottomLeftRadius="10dp"
/>
<!--stroke里是边框的宽度和颜色-->
<stroke
android:width="1dp"
android:color="@android:color/holo_blue_light"
/>
</shape>


2、二是在布局文件里调用这个资源:

<?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:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
tools:context="com.example.test.MainActivity">
<!--在background里设置就好-->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/myedittext"
/>
</RelativeLayout>


3、最后来看一下效果

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐