login界面 checkbox选择显示或者隐藏密码
来源:互联网 发布:aws没有centos 编辑:程序博客网 时间:2024/06/11 10:23
先来看看布局文件login.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" android:orientation="vertical" tools:context="com.example.demotest.MainActivity" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="账号:" /> <EditText android:id="@+id/edtlogin" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1000" android:hint="输入账号" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密码:" /> <EditText android:id="@+id/edtpassword" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:hint="输入密码" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="30dp" > <CheckBox android:id="@+id/checkbox" android:layout_width="126dp" android:layout_height="wrap_content" android:text="显示密码" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:id="@+id/zhuchebtn" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="注册" /> <Button android:id="@+id/loginbtn" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="登录" /> </LinearLayout></LinearLayout>
就是很简单的登录界面,我就不多解释了。
下面我们来看mainActivity.class的代码
public class MainActivity extends Activity { private Button loginbtn; private EditText edtname; private EditText edtpassword; private String name; private String password; private CheckBox checkbox; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login); loginbtn = (Button) findViewById(R.id.loginbtn); edtname = (EditText) findViewById(R.id.edtlogin); edtpassword = (EditText) findViewById(R.id.edtpassword); checkbox = (CheckBox) findViewById(R.id.checkbox); checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if (!isChecked) { edtpassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); } else { edtpassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); } } }); loginbtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { name = edtname.getText().toString(); password = edtpassword.getText().toString(); // TODO Auto-generated method stub if (name.equals("jaytang") && password.equals("4011")) { Intent intent = new Intent(MainActivity.this, Weixin.class); startActivity(intent); } else { Toast.makeText(MainActivity.this, "false", Toast.LENGTH_SHORT).show(); } } }); }}
主要看那个checkbox的监听事件
checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if (!isChecked) { edtpassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); } else { edtpassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); } } });
0 0
- login界面 checkbox选择显示或者隐藏密码
- ubuntu 显示或者隐藏 grub选择菜单
- ubuntu 显示或者隐藏 grub选择菜单
- ListView+CheckBox实现全部隐藏或者显示问题
- android使用CheckBox显示隐藏输入的密码
- android 根据checkBox动态控制密码的显示和隐藏
- 通过checkBox复选框来隐藏和显示密码
- 在WINDOWS登录界面上显示或者隐藏administrator用户
- 代码中设置EditText显示或者隐藏密码
- 显示密码,隐藏密码
- login界面,判断是否是最后一个图片,如果不是则隐藏,是则显示
- 1.自定义checkbox 2.根据checkbox让密码显示与隐藏
- 注册界面密码的动态显示和隐藏
- Android基础--登陆界面,密码的隐藏和显示
- 隐藏,或者显示
- 显示或者隐藏文件
- element隐藏或者显示
- js显示或者隐藏
- 几个不错的网站,在写email的html的时候会用到
- 安卓008移动存储--SharePreference
- Python网络编程-主机-虚拟机之间TCP协议简单通信实例
- android下netperf测试网卡网速能力
- Web前端教程js-event(事件对象及其属性、方法)
- login界面 checkbox选择显示或者隐藏密码
- JDBCUtil模板
- Tricks(三十六)—— remove_list_entry(无需 if 逻辑)
- 练习18:函数
- 官网Red Hat Enterprise Linux 6 Power Management Guide
- innerHTML和innerText的使用方法
- solve 解方程
- jar包的创建与使用
- LeetCode-6. ZigZag Conversion