android实现密码框右侧显示小眼睛
作者:键盘侠007 发布时间:2023-01-26 19:54:59
标签:android,密码框
本文实例为大家分享了android实现密码框右侧显示小眼睛的具体代码,供大家参考,具体内容如下
实现效果
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="12dp" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:paddingTop="10dp"
android:background="@drawable/selector_sign"
android:id="@+id/et_usertel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:hint="@string/editText_phont"
android:inputType="phone"
android:paddingLeft="90dp"
android:singleLine="true"
android:textColorHint="#DDDDDD"
android:textSize="16sp" />
<EditText
android:id="@+id/edt_chosed_country_num"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/et_usertel"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="@color/white"
android:inputType="number"
android:maxLength="5"
android:text="+86"
android:textColor="#353535"
android:textSize="16sp" />
</RelativeLayout>
<LinearLayout
android:id="@+id/linear_password_code"
android:visibility="visible"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:background="@drawable/selector_sign"
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:paddingTop="10dp"
android:hint="@string/editText_code"
android:paddingLeft="90dp"
android:singleLine="true"
android:textColorHint="#DDDDDD"
android:textSize="16sp" />
<Button
android:id="@+id/bu_register_code"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignRight="@+id/et_password"
android:layout_marginRight="2dp"
android:background="@drawable/shape_border_color_primary_sign"
android:text="@string/verification_code"
android:textColor="@drawable/selector_text_color_primary"
android:textSize="16sp" />
<!-- <View
android:layout_marginTop="1dp"
android:layout_alignBottom="@+id/bu_code"
android:layout_width="290dp"
android:layout_height="1dp"
android:background="@color/light_grey"/>-->
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/password_liner"
android:visibility="gone"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:background="@drawable/selector_sign"
android:id="@+id/et_password_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:paddingTop="10dp"
android:hint="请输入密码登录"
android:paddingLeft="90dp"
android:singleLine="true"
android:textColorHint="#DDDDDD"
android:inputType="textPassword"
android:textSize="16sp" />
<ImageView
android:id="@+id/imageView"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_margin="10dp" />
</RelativeLayout>
</LinearLayout>
<Button
android:textColor="@color/background"
android:layout_marginTop="10dp"
android:background="@drawable/shape_color_primary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="登录"/>
<LinearLayout
android:layout_marginTop="2dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textStyle="bold"
android:gravity="center"
android:text="使用密码登录 >"
android:id="@+id/tv_register_login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
//主要代码如下
<LinearLayout
android:id="@+id/password_liner"
android:visibility="gone"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:background="@drawable/selector_sign"
android:id="@+id/et_password_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:paddingTop="10dp"
android:hint="请输入密码登录"
android:paddingLeft="90dp"
android:singleLine="true"
android:textColorHint="#DDDDDD"
android:inputType="textPassword"
android:textSize="16sp" />
<ImageView
android:id="@+id/imageView"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_margin="10dp" />
</RelativeLayout>
</LinearLayout>
重要代码
private boolean isHideFirst = true;// 输入框密码是否是隐藏的,默认为true
if (isHideFirst == true) {
imageView.setImageResource(R.drawable.open);
//密文
HideReturnsTransformationMethod method1 = HideReturnsTransformationMethod.getInstance();
et_password_code.setTransformationMethod(method1);
isHideFirst = false;
} else {
imageView.setImageResource(R.drawable.close);
//密文
TransformationMethod method = PasswordTransformationMethod.getInstance();
et_password_code.setTransformationMethod(method);
isHideFirst = true;
}
// 光标的位置
int index = et_password_code.getText().toString().length();
et_password_code.setSelection(index);
package com.ynrd.entrepreneur.activity;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.text.method.TransformationMethod;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.ynrd.entrepreneur.R;
import com.ynrd.entrepreneur.utils.CountDownTimerUtils;
public class RegisterActivity extends BaseCommonActivity implements View.OnClickListener {
private Button bu_register_code;
private TextView tv_register_login_password;
private boolean isHideFirst = true;// 输入框密码是否是隐藏的,默认为true
private boolean isFirst = true;// 是否密码登录,默认是验证码登录
private ImageView imageView;
private EditText et_password_code;
private LinearLayout linear_password_code,password_liner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
}
@Override
protected void initViews() {
super.initViews();
//获取验证码
bu_register_code = findViewById(R.id.bu_register_code);
tv_register_login_password = findViewById(R.id.tv_register_login_password);
imageView = findViewById(R.id.imageView);
et_password_code = findViewById(R.id.et_password_code);
linear_password_code = findViewById(R.id.linear_password_code);
password_liner = findViewById(R.id.password_liner);
}
@Override
protected void initListeners() {
super.initListeners();
bu_register_code.setOnClickListener(this);
tv_register_login_password.setOnClickListener(this);
imageView.setOnClickListener(this);
imageView.setImageResource(R.drawable.close);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.bu_register_code:
//验证码方法 后期调用服务器
CountDownTimerUtils mCountDownTimerUtils = new CountDownTimerUtils(bu_register_code, 30000, 1000);
mCountDownTimerUtils.start();
break;
case R.id.tv_register_login_password:
if (isFirst == true){
//切换成密码登录
linear_password_code.setVisibility(View.GONE);
password_liner.setVisibility(View.VISIBLE);
tv_register_login_password.setText("使用短信验证码登录 >");
isFirst = false;
}else{
//切换成验证码登录
linear_password_code.setVisibility(View.VISIBLE);
password_liner.setVisibility(View.GONE);
tv_register_login_password.setText("使用密码登录 >");
isFirst = true;
}
break;
case R.id.imageView:
if (isHideFirst == true) {
imageView.setImageResource(R.drawable.open);
//密文
HideReturnsTransformationMethod method1 = HideReturnsTransformationMethod.getInstance();
et_password_code.setTransformationMethod(method1);
isHideFirst = false;
} else {
imageView.setImageResource(R.drawable.close);
//密文
TransformationMethod method = PasswordTransformationMethod.getInstance();
et_password_code.setTransformationMethod(method);
isHideFirst = true;
}
// 光标的位置
int index = et_password_code.getText().toString().length();
et_password_code.setSelection(index);
break;
}
}
}
来源:https://blog.csdn.net/qq_29072049/article/details/108829453


猜你喜欢
- 本文实例为大家分享了Javaweb统计在线人数示的具体代码,供大家参考,具体内容如下1. 实现功能统计在线人数显示每个人的sessionId
- 一、使用嵌入式关系型SQLite数据库存储数据在Android平台上,集成了一个嵌入式关系型数据库——SQLite,SQLite3支持NUL
- 1.基本介绍SpringBoot 支持的 webServer: Tomcat, Jetty, or UndertowSpringBoot 应
- 集成配置步骤步骤1:加入 Maven 相关依赖<!-- 指定 Springboot 版本 --><parent> &
- C语言数据结构基本算法希尔排序前言:基本思想:算法先将要排序的一组数按某个增量d(n/2,n为要排序数的个数)分成若干组,每组中记录的下标相
- 前言虽然Android程序是使用Java语言开发的,当然,现在也可以使用kotlin语言。但是实际上我们开发出来的Android程序并不能运
- 分页插件  MP中自带了分页插件的功能,只需要在配置类中进行简单的配置即可使用分页的相关功能。分页插件常
- Contact联系人对Mms来说是十分重要的,因为每一个对话的收信人都是一个联系人,新建信息时可以输入联系人的任何信息,比如号码或名字,Mm
- 前言该篇文章主要总结的是自己平时工作中使用频率比较高的Xml文档操作的一些常用方法和收集网上写的比较好的一些通用Xml文档操作的方法(主要包
- C#中Invoke的用法()invoke和begininvoke 区别一直对invoke和begininvoke的使用和概念比较混乱,这两天
- 今天有同事用swagger2开发时,有一方法返回Map<String,List<Object>>出现无法解析错误。P
- 1、HashMap HashMap继承抽象类AbstractMap,实现接口Map、Cloneable, Serializable接口。Ha
- 1. 将对象转换为JSON字符串,返回值为一个JSON字符串public static String toJson(Object value
- 目录Profile用法resourcesfilters多环境配置解决方案Profile用法我们在application.yml中为jdbc.
- 本文主要给大家介绍的是关于Android实现微信雷达扫描效果的相关内容,分享出来供大家参考学习,下面来看看详细的介绍:废话不多说 先上图(用
- 在servlet3.0标准之前,是每一个请求对应一个线程。如果此时一个线程出现了高延迟,就会产生阻塞问题,从而导致整个服务出现严重的性能情况
- 前言:在 Spring 中, IOC 是很重要的概念,其本质就是 map 结构,存储容器和业务 Be
- FileStream对象表示在磁盘或网络路径上指向文件的流。这个类提供了在文件中读写字节的方法,但经常使用StreamReader或Stre
- 6.0的手机对于写入手机需要申请权限的我做了如下处理下面我贴出代码package com.example.admin.sdapplicati
- 一、前台服务的简单介绍前台服务是那些被认为用户知道且在系统内存不足的时候不允许系统杀死的服务。前台服务必须给状态栏提供一个通知,它被放到正在