Android 密码的隐藏和显示

在Android开发中,需要密码的隐藏和显示,下面就和大家分享一下使用方法:
xml代码:

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="@color/white"
            android:orientation="horizontal" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="新密码"
                android:textColor="@color/black"
                android:textSize="18dp"
                android:gravity="center_vertical"
                android:layout_marginLeft="15dp"/>

            <EditText
                android:id="@+id/newpassword"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="match_parent"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="10dp"
                android:inputType="textPassword"
                android:hint="请设置登录密码"
                android:background="@null"/>

            <CheckBox
                android:id="@+id/CheckBox"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginRight="15dp"
                android:textSize="16dp"
                android:text="显示"
                />

        </LinearLayout>

####隐藏图标代码

android:button="@null"

JAVA代码:

/**
 * Created by fby on 2017/9/11.
 */

public class ChargepsdActivity extends Activity {

    private EditText editText;
    private CheckBox checkBox;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chargepsd);

        editText = (EditText) findViewById(R.id.newpassword);
        checkBox = (CheckBox) findViewById(R.id.CheckBox);

        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                if(isChecked){
                    //如果选中,显示密码
                    editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                }else{
                    //否则隐藏密码
                    editText.setTransformationMethod(PasswordTransformationMethod.getInstance());

                }

            }
        });

    }
}

效果展示:

隐藏

显示

Android开发~获取验证码倒计时实现

希望可以帮助大家
如果哪里有什么不对或者不足的地方,还望读者多多提意见或建议
Android技术交流群:591625129

源码Demo获取方法

关注「网罗开发」公众号 ,有iOS demo、RN 视频以及demo、Android demo等你领取。


在这里插入图片描述

小专栏:https://xiaozhuanlan.com/u/fanbaoying

  • 0
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

网罗开发

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值