android控制密码显示与隐藏的方法

本文实例为大家分享了android控制密码显示与隐藏的具体代码,供大家参考,具体内容如下

<RelativeLayout
            android:id="@+id/view2"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_marginTop="20dp">

            <TextView
                android:id="@+id/tv_phone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginStart="15dp"
                android:text="新密码:"
                android:textColor="@color/font_color_11"
                android:textSize="16sp" />

            <EditText
                android:id="@+id/et_phone"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginEnd="15dp"
                android:layout_toEndOf="@id/tv_phone"
                android:background="@null"
                android:paddingStart="10dp"
                android:password="true"
                android:text="18333619388"
                android:textColor="@color/textcolor"
                android:textSize="16sp" />

            <ImageView
                android:id="@+id/iv_newpw"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="-60dp"
                android:layout_toEndOf="@id/et_phone"
                android:background="@mipmap/uneye" />

            <View
                android:layout_width="match_parent"
                android:layout_height="0.5dp"
                android:layout_alignParentBottom="true"
                android:layout_marginLeft="18.5dp"
                android:layout_marginRight="18.5dp"
                android:background="@color/base_color_2" />
</RelativeLayout>
private ImageView ivNewpw;
private EditText etPhone;

ivNewpw = (ImageView) findViewById(R.id.iv_newpw);
etPhone = (EditText) findViewById(R.id.et_phone);
ivNewpw.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TransformationMethod method = etPhone.getTransformationMethod();
                if (method == HideReturnsTransformationMethod.getInstance()) {
                    etPhone.setTransformationMethod(PasswordTransformationMethod.getInstance());
                    ivNewpw.setBackgroundResource(R.mipmap.uneye);
                } else {
                    etPhone.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                    ivNewpw.setBackgroundResource(R.mipmap.eye);
                }
            }
        });

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • Android中实现密码的隐藏和显示的示例

    在Android开发中,需要密码的隐藏和显示,下面就和大家分享一下使用方法: xml代码: <LinearLayout android:layout_width="match_parent" android:layout_height="50dp" android:background="@color/white" android:orientation="horizontal" > <TextView an

  • Android EditText密码的隐藏和显示功能

    Android EditText密码的隐藏和显示功能 实现效果图: 实现代码: 首先在xml里创建两个控件 EditText和CheckBox 然后就很简单了 dt1=(EditText)findViewById(R.id.password); cb1=(CheckBox)findViewById(R.id.checkbox_1); cb1.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public vo

  • 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

  • Android实现显示和隐藏密码功能的示例代码

    在前端中我们知道用javascript就可以可以很容易实现,那么在Android中怎么实现这个功能呢? Java代码 package com.example.test2; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.text.method.HideReturnsTransformationMethod; import android.text.method.Pa

  • Android文本输入框(EditText)输入密码时显示与隐藏

    代码很简单,这里就不多废话了. 复制代码 代码如下: package cc.c; import android.app.Activity; import android.os.Bundle; import android.text.Selection; import android.text.Spannable; import android.text.method.HideReturnsTransformationMethod; import android.text.method.Passw

  • Android中实现EditText密码显示隐藏的方法

    在Google发布了support:design:23+以后我们发现有这么一个东西TextInputLayout,先看下效果图: <android.support.design.widget.TextInputLayout android:id="@+id/pwdLayout" android:layout_width="match_parent" android:layout_height="wrap_content" app:passw

  • Android开发EditText实现密码显示隐藏

    最近在做一个登录.注册页面,里面需要显示或隐藏密码,故做了一个简单的显示和隐藏功能. 关键类TextView.setTransformationMethod(TransformationMethod method),其中TransformationMethod 有两个子类: HideReturnsTransformationMethod 隐藏回车 PasswordTransformationMethod 密码类型 关键代码: @OnClick(R.id.iv_psw_eye)     void

  • Android实现动态显示或隐藏密码输入框的内容

    本文实例展示了Android实现动态显示或隐藏密码输入框内容的方法,分享给大家供大家参考之用.具体方法如下: 该功能可通过设置EditText的setTransformationMethod()方法来实现隐藏密码或者显示密码. 示例代码如下: private Button mBtnPassword; private EditText mEtPassword; private boolean mbDisplayFlg = false; /** Called when the activity is

  • Android实现密码隐藏和显示

    本文实例为大家分享了Android实现密码隐藏和显示的具体代码,供大家参考,具体内容如下 在Android开发中,需要密码的隐藏和显示,下面就和大家分享一下使用方法: xml代码: <LinearLayout              android:layout_width="match_parent"             android:layout_height="50dp"             android:background="

  • Android 登录页面的实现代码(密码显示隐藏、EditText 图标切换、限制输入长度)

    效果演示 密码显示与隐藏 方法一 if(status){ etPassword.setInputType(InputType.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_NORMAL); //显示文本 status = false; }else { etPassword.setInputType(InputType.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_PASSWORD); //隐藏

随机推荐