展会信息港展会大全

Android设置EditText为密码样式
来源:互联网   发布日期:2016-01-14 12:26:01   浏览:2334次  

导读:package zhang.example; import android.app.Activity; import android.os.Bundle; import android.text.method.HideReturnsTransformationMethod; import android.text.method.PasswordTransformationMethod; import android.widget.CheckBox; import andro...

package zhang.example;

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.EditText;

import android.widget.CompoundButton.OnCheckedChangeListener;

public class seefm extends Activity {

private EditText ed;

private CheckBox cb;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

ed = (EditText) findViewById(R.id.editText1);

cb = (CheckBox) findViewById(R.id.checkBox1);

cb.setChecked(false);

cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

@Override

public void onCheckedChanged(CompoundButton arg0, boolean arg1) {

// TODO Auto-generated method stub

if (cb.isChecked())

ed.setTransformationMethod(HideReturnsTransformationMethod

.getInstance());

else

ed.setTransformationMethod(PasswordTransformationMethod

.getInstance());

}

});

}

}

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello" />

<EditText

android:id="@+id/editText1"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="输入密码">

</EditText>

<CheckBox

android:id="@+id/checkBox1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="点击显示密码">

</CheckBox>

</LinearLayout>

赞助本站

人工智能实验室

相关热词: Android 设置 EditText

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港