Android开发中密码显示隐藏功能的操作方法
来源:爱站网时间:2021-01-22编辑:网友分享
当我们在编写Android应用程序的时候,需要安装APK文件,但在某些情况下,我们需要在应用列表中隐藏已安装的应用,接下来爱站技术频道给大家具体介绍Android开发中密码显示隐藏功能的操作方法,希望能对你有所帮助。
当我们在编写Android应用程序的时候,需要安装APK文件,但在某些情况下,我们需要在应用列表中隐藏已安装的应用,接下来爱站技术频道给大家具体介绍Android开发中密码显示隐藏功能的操作方法,希望能对你有所帮助。
效果:


package com.example.test;
import android.app.Activity;
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.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView editText1;
private CheckBox checkBox1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
editText1 =(TextView) findViewById(R.id.editText1);
checkBox1=(CheckBox) findViewById(R.id.checkBox1);
checkBox1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked){
//如果选中,显示密码
editText1.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
}else{
//否则隐藏密码
editText1.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
}
});
}
}
关键是:
editText1.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); editText1.setTransformationMethod(PasswordTransformationMethod.getInstance());
以上内容就是爱站技术频道小编带给大家的Android开发中密码显示隐藏功能的操作方法,这里的专业技能是非常强大的,可以给诸多程序员解决燃眉之急。
