首页 > 移动平台 > 详细

Android开发之密码明文密文切换显示

时间:2015-05-02 15:16:16      阅读:1019      评论:0      收藏:0      [点我收藏+]

.xml文件

<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"

    tools:context=".MainActivity" 

    android:orientation="vertical">


    <TextView

        android:id="@+id/msg"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="用户密码" />

    <EditText 

        android:id="@+id/edit"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:password="true"/>

    

    <CheckBox 

        android:id="@+id/show"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="显示密码"/>


</LinearLayout>


.java文件

public class MainActivity extends Activity {

private EditText passwd=null;

private CheckBox show=null;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

this.passwd=(EditText) super.findViewById(R.id.edit);

this.show=(CheckBox) super.findViewById(R.id.show);

this.show.setOnClickListener(new OnclickListenerImp());

}


private class OnclickListenerImp implements OnClickListener{


public void onClick(View v) {

if(MainActivity.this.show.isChecked()){

//设置为明文显示

MainActivity.this.passwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance());

}

else{

//设置为秘闻显示

MainActivity.this.passwd.setTransformationMethod(PasswordTransformationMethod.getInstance());

}

}

}


}



Android开发之密码明文密文切换显示

原文:http://my.oschina.net/u/1244156/blog/409073

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!