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

相关文章

  • Android SeekBar充当Progress实现兔兔进度条Plus

    Android SeekBar充当Progress实现兔兔进度条Plus

    这篇文章主要为大家介绍了Android SeekBar充当Progress实现兔兔进度条Plus示例,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-02-02
  • Android App中使用AudioManager类来编写音频播放器

    Android App中使用AudioManager类来编写音频播放器

    这篇文章主要介绍了Android App中使用AudioManager类来编写音乐播放器的方法,文中举了一个简单的例子实现了基础的播放暂停和静音等功能,需要的朋友可以参考下
    2016-04-04
  • Android 高德地图之poi搜索功能的实现代码

    Android 高德地图之poi搜索功能的实现代码

    这篇文章主要介绍了android 高德地图之poi搜索功能的实现代码,在实现此功能时遇到很多问题,在文章都给大家提到,需要的朋友可以参考下
    2017-08-08
  • Android自定义水平进度条的圆角进度

    Android自定义水平进度条的圆角进度

    这篇文章主要为大家详细介绍了Android自定义水平进度条的圆角进度,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2016-08-08
  • OkHttp原理分析小结

    OkHttp原理分析小结

    OkHttp 是 Square 公司开源的一款网络框架,封装了一个高性能的 http 请求库,本文对OkHttp原理给大家详细讲解,感兴趣的朋友跟随小编一起看看吧
    2024-01-01
  • Jenkins打包android应用时自动签名apk详解

    Jenkins打包android应用时自动签名apk详解

    这篇文章主要介绍了Jenkins打包android应用时自动签名apk详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2019-07-07
  • Android实现通过手势控制图片大小缩放的方法

    Android实现通过手势控制图片大小缩放的方法

    这篇文章主要介绍了Android实现通过手势控制图片大小缩放的方法,结合实例形式分析了Android控制图片缩放的原理、实现步骤与相关操作技巧,需要的朋友可以参考下
    2016-10-10
  • java反射android的r文件的示例

    java反射android的r文件的示例

    这篇文章主要介绍了java反射android的r文件的示例,动态取得R文件的int值,需要的朋友可以参考下
    2014-04-04
  • Android Flutter实现搜索的三种方式详解

    Android Flutter实现搜索的三种方式详解

    这篇文章主要为大家详细介绍了Android Flutter实现搜索的三种方式,文中的示例代码讲解详细,具有一定的借鉴价值,感兴趣的可以了解一下
    2022-08-08
  • Flutter开发之路由与导航的实现

    Flutter开发之路由与导航的实现

    这篇文章主要介绍了Flutter开发之路由与导航的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-12-12

最新评论