欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > > 内容正文

AndroidEditText设置边框的操作方法,

来源: 开发者 投稿于  被查看 47833 次 评论:208

AndroidEditText设置边框的操作方法,


目录
  • 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边框内容请搜索3672js教程以前的文章或继续浏览下面的相关文章希望大家以后多多支持3672js教程!

您可能感兴趣的文章:
  • Android中EditText如何去除边框添加下划线
  • Android中EditText光标的显示与隐藏方法
  • Android EditText每4位自动添加空格效果
  • Android EditText监听回车键并处理两次回调问题
  • Android实现EditText添加下划线

用户评论