• EditText隐藏和显示


    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 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:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.pingyijinren.helloworld.MainActivity"
        android:orientation="vertical">
    
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/editText"
            android:password="true"/>
    
        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/checkBox"/>
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="显示密码"/>
    </LinearLayout>
    package com.pingyijinren.helloworld;
    
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.text.method.HideReturnsTransformationMethod;
    import android.text.method.PasswordTransformationMethod;
    import android.widget.CheckBox;
    import android.widget.CompoundButton;
    import android.widget.EditText;
    
    public class MainActivity extends AppCompatActivity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            final EditText editText=(EditText)findViewById(R.id.editText);
            final CheckBox checkBox=(CheckBox)findViewById(R.id.checkBox);
            checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if(checkBox.isChecked()){
                        editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                    }
                    else{
                        editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
                    }
                }
            });
        }
    }
  • 相关阅读:
    Spine(2D骨骼动画)
    UpdatePanel的用法
    Windows7下的免费虚拟机(微软官方虚拟机)
    android ViewPager具体解释
    与Scheme共舞
    Binder机制1---Binder原理介绍
    HDU 2853 Assignment(KM最大匹配好题)
    微信公众平台java开发具体解释(project代码+解析)
    怎样绕过oracle listener 监听的password设置
    IOS成长之路-Nsstring中搜索方法rangeOfString
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/5549631.html
Copyright © 2020-2023  润新知