Android EditText设置边框的操作方法
(福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun)
Android EditText设置边框
简介
Android应用程序中给EditText设置边框。
效果图:
快速开始
1.在res/drawable目录下新建样式文件 edit_background.xml。
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <solid android:color="#efefef"/> <corners android:radius="5dp"/> <stroke android:width="1dp" android:color="#505050"/> </shape> </item>
2.布局文件中使用边框效果,/res/layout/activity_edit_text.xml。
android:background=“@drawable/edit_background”
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".EditTextActivity"> <TextView android:id="@+id/name_label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="账号:" android:textSize="18sp" android:textColor="#353535" android:layout_marginTop="60dp" android:layout_marginStart="60dp" app:layout_constraintTop_toTopOf="parent" app:layout_constraintLeft_toLeftOf="parent"/> <EditText android:id="@+id/edit_name" android:layout_width="200dp" android:layout_height="40dp" android:hint="请输入账号" android:gravity="center" android:inputType="number" android:background="@drawable/edit_background" android:layout_marginStart="10dp" app:layout_constraintTop_toTopOf="@id/name_label" app:layout_constraintBottom_toBottomOf="@id/name_label" app:layout_constraintLeft_toRightOf="@id/name_label"/> <TextView android:id="@+id/pwd_label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密码:" android:textSize="18sp" android:textColor="#353535" android:layout_marginTop="40dp" android:layout_marginStart="60dp" app:layout_constraintTop_toBottomOf="@id/name_label" app:layout_constraintLeft_toLeftOf="parent"/> <EditText android:id="@+id/edit_pwd" android:layout_width="200dp" android:layout_height="40dp" android:hint="请输入密码" android:gravity="center" android:inputType="textPassword" android:background="@drawable/edit_background" android:layout_marginStart="10dp" app:layout_constraintTop_toTopOf="@id/pwd_label" app:layout_constraintBottom_toBottomOf="@id/pwd_label" app:layout_constraintLeft_toRightOf="@id/pwd_label"/> <Button android:id="@+id/btn_login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="ok" android:layout_marginTop="30dp" android:layout_marginStart="110dp" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toBottomOf="@id/pwd_label"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Cancel" android:layout_marginStart="50dp" app:layout_constraintTop_toTopOf="@id/btn_login" app:layout_constraintLeft_toRightOf="@id/btn_login"/> </android.support.constraint.ConstraintLayout>
到此这篇关于Android EditText设置边框的文章就介绍到这了,更多相关Android EditText边框内容请搜索程序员之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持程序员之家!
相关文章
android换肤功能 如何动态获取控件中背景图片的资源id?
这篇文章主要为大家详细介绍了android换肤功能中如何动态获取控件中背景图片的资源id? ,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2016-08-08Android中AlertDialog 点击按钮后不关闭对话框的功能
本篇文章主要介绍了Android中AlertDialog 点击按钮后不关闭对话框的功能,非常具有实用价值,需要的朋友可以参考下2017-04-04Android?源码浅析RecyclerView?Adapter
这篇文章主要介绍了Android?源码浅析之RecyclerView?Adapter示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2022-12-12
最新评论