Android EditText设置边框的操作方法

 更新时间:2023年12月19日 11:07:38   作者:tracydragonlxy  
这篇文章主要介绍了Android EditText设置边框,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

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边框内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • Flutter 枚举值enum和int互相转化总结

    Flutter 枚举值enum和int互相转化总结

    这篇文章主要为大家介绍了Flutter 枚举值enum和int互相转化总结分析,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-02-02
  • Android实现购物商城

    Android实现购物商城

    这篇文章主要为大家详细介绍了Android实现购物商城,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-04-04
  • Android仿淘宝详情页面viewPager滑动到最后一张图片跳转的功能

    Android仿淘宝详情页面viewPager滑动到最后一张图片跳转的功能

    需要做一个仿淘宝客户端ViewPager滑动到最后一页,再拖动的时候跳到详情的功能,刚开始我也迷糊了,通过查阅相关资料发现有好多种实现方法,下面小编给大家分享实例代码,感兴趣的朋友一起看看吧
    2017-03-03
  • Android中应用前后台切换监听的实现详解

    Android中应用前后台切换监听的实现详解

    这篇文章主要给大家介绍了关于Android中应用前后台切换监听实现的相关资料,文中通过示例代码介绍的非常详细,对大家具有一定的参考学习价值,需要的朋友们下面跟着小编来一起学习学习吧。
    2017-07-07
  • 详解Android安全防护之加密算法

    详解Android安全防护之加密算法

    Android应用对安全防范这方面要求越来越高了。特别是金融行业,如果app没有没有做好安全处理,那些很容易被一些Hacker(黑客)所攻击。并不是说做了这些安全防范,这个应用就百分之百的安全的。只是说能够尽可能加大破解难度。本文将详细介绍Android安全防护之加密算法。
    2021-06-06
  • Android给通知channel静音的方法实例

    Android给通知channel静音的方法实例

    这篇文章主要给大家介绍了关于Android如何给通知channel静音的相关资料,文中通过实例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2022-02-02
  • Android App使用RecyclerView实现上拉和下拉刷新的方法

    Android App使用RecyclerView实现上拉和下拉刷新的方法

    RecyclerView一经推出便被认为是替代ListView的存在,那么ListView的上拉和下拉刷新我们同样可以使用RecyclerView来做到,这里我们就来看一下Android App使用RecyclerView实现上拉和下拉刷新的方法,首先先来点RecyclerView的小介绍:
    2016-06-06
  • ubuntu下 AndroidStudio4.1启动报错问题的解决

    ubuntu下 AndroidStudio4.1启动报错问题的解决

    这篇文章主要介绍了ubuntu下 AndroidStudio4.1启动报错问题的解决,本文给大家分享个人经验对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-10-10
  • 基于DownloadManager的简单下载器编写小结

    基于DownloadManager的简单下载器编写小结

    Android自带的DownloadManager是一个很好的下载文件的工具。该类在API level 9之后出现,它已经帮我们处理了下载失败、重新下载等功能,整个下载过程全部交给系统负责,不需要我们过多的处理,非常的nice。关键的是用起来也很简单,稍微封装一下就可以几句话搞定下载
    2017-12-12
  • Android实现读写USB串口数据

    Android实现读写USB串口数据

    这篇文章主要为大家详细介绍了Android实现读写USB串口数据,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-09-09

最新评论