Android EditText设置边框的操作方法

 更新时间:2023年12月19日 11:07:38   作者:tracydragonlxy  
这篇文章主要介绍了Android EditText设置边框,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
(福利推荐:【腾讯云】服务器最新限时优惠活动,云服务器1核2G仅99元/年、2核4G仅768元/3年,立即抢购>>>:9i0i.cn/qcloud

(福利推荐:你还在原价购买阿里云服务器?现在阿里云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如何实现APP自动更新

    Android如何实现APP自动更新

    现在一般的android软件都是需要不断更新的,当你打开某个app的时候,如果有新的版本,它会提示你有新版本需要更新。该小程序实现的就是这个功能。有需要的朋友们可以参考借鉴。
    2016-08-08
  • android换肤功能 如何动态获取控件中背景图片的资源id?

    android换肤功能 如何动态获取控件中背景图片的资源id?

    这篇文章主要为大家详细介绍了android换肤功能中如何动态获取控件中背景图片的资源id? ,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2016-08-08
  • Android中AlertDialog 点击按钮后不关闭对话框的功能

    Android中AlertDialog 点击按钮后不关闭对话框的功能

    本篇文章主要介绍了Android中AlertDialog 点击按钮后不关闭对话框的功能,非常具有实用价值,需要的朋友可以参考下
    2017-04-04
  • Android中使用adb命令通过IP地址连接手机

    Android中使用adb命令通过IP地址连接手机

    这篇文章主要介绍了Android中使用adb命令通过IP地址连接手机的方法,本文给大家分享两种解决方法 ,需要的朋友可以参考下
    2018-07-07
  • android如何设置Activity背景色为透明色

    android如何设置Activity背景色为透明色

    本篇文章主要介绍了android如何设置Activity背景色为透明色,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-07-07
  • Android实现仿360桌面悬浮清理内存

    Android实现仿360桌面悬浮清理内存

    今天给大家带来一个仿360手机卫士悬浮窗清理内存的效果的教程,非常的简单实用,需要的小伙伴可以参考下
    2015-12-12
  • Android仿搜狐视频、微视等列表播放视频功能

    Android仿搜狐视频、微视等列表播放视频功能

    这篇文章主要为大家详细介绍了Android仿搜狐视频、微视等列表播放视频功能,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-08-08
  • Android?源码浅析RecyclerView?Adapter

    Android?源码浅析RecyclerView?Adapter

    这篇文章主要介绍了Android?源码浅析之RecyclerView?Adapter示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-12-12
  • Android多线程AsyncTask详解

    Android多线程AsyncTask详解

    这篇文章主要为大家详细介绍了Android多线程AsyncTask的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-08-08
  • Android实现边录边播应用

    Android实现边录边播应用

    这篇文章主要为大家详细介绍了Android实现边录边播应用,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-11-11

最新评论

?


http://www.vxiaotou.com