AS edit view 代码 简单实现

一、layout代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp">

<TextView
    android:id="@+id/db"
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="112dp"
    android:layout_marginTop="25dp"
    android:background="@drawable/fj" />

<EditText
    android:id="@+id/ed_01"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_below="@id/db"
    android:layout_marginTop="20dp"
    android:textColor="#ff0000"
    android:textSize="16sp"
    android:hint="用户名/账号"
    android:inputType="number"
    android:drawableLeft="@mipmap/username"
    android:background="@drawable/bg_btn03"
    />
<EditText
    android:id="@+id/ed_02"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_marginTop="35dp"
    android:textColor="#ff0000"
    android:textSize="16sp"
    android:layout_below="@+id/ed_01"
    android:hint="密码"
    android:inputType="textPassword"
    android:drawableLeft="@mipmap/passwd"
    android:background="@drawable/bg_btn03"
    />
<Button
    android:id="@+id/btn_dl"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:text="点我登录"
    android:textSize="18sp"
    android:layout_marginTop="20dp"
    android:layout_below="@id/ed_02"
    android:background="@drawable/bg_btn05"
    />

</RelativeLayout>

二、java代码

package com.relativelayout;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class EditViewActivity extends AppCompatActivity {
private Button btn_login;
private EditText ed01;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_view);
    btn_login = findViewById(R.id.btn_dl);
    btn_login.setOnClickListener(new View.OnClickListener() {
        @Override
        //弹窗提示
        public void onClick(View v) {
            Toast.makeText(EditViewActivity.this,"登录成功!",Toast.LENGTH_SHORT).show();
        }
    });
    ed01 = findViewById(R.id.ed_01);
    ed01.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }
        //内容更改正当时捕捉。此处添加后可能会报错,根据报错信息修改即可
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            String content = s.toString();
            Log.d("editViewUser",content);
            Log.d("length:",String.valueOf(content.length()));

        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });
}

}

附图:
在这里插入图片描述

本文不再做单独说明,大多属性前面博客已有注释,部分属性望文生义,极少部分属性可自行百度。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值