1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. android:padding="3dip"
  7. >
  8.  
  9. <!--0固定1可以扩展-->
  10.  
  11. <TableLayout
  12. android:layout_width="fill_parent"
  13. android:layout_height="wrap_content"
  14. android:numColumns="8"
  15. android:shrinkColumns="0"
  16. android:stretchColumns="1">
  17.  
  18. <TableRow
  19. android:layout_width="fill_parent"
  20. android:layout_height="wrap_content">
  21.  
  22. <TextView
  23. android:id="@+id/label"
  24. android:layout_width="wrap_content"
  25. android:layout_height="wrap_content"
  26. android:text="请输入用户名:" />
  27. <!-- 这个EditText放置在上边id为label的TextView的下边 -->
  28. <EditText
  29. android:id="@+id/username"
  30. android:layout_width="fill_parent"
  31. android:layout_height="wrap_content"
  32. android:layout_below="@id/label"
  33. android:background="@android:drawable/editbox_background" />
  34.  
  35. </TableRow>
  36. <TableRow>
  37.  
  38. <TextView
  39. android:id="@+id/label1"
  40. android:layout_width="wrap_content"
  41. android:layout_height="wrap_content"
  42. android:text="密码:" />
  43. <!-- 这个EditText放置在上边id为label的TextView的下边 -->
  44. <EditText
  45. android:id="@+id/pass"
  46. android:layout_width="fill_parent"
  47. android:layout_height="wrap_content"
  48. android:layout_below="@id/label1"
  49. android:inputType="textPassword"
  50. android:background="@android:drawable/editbox_background" />
  51. <CheckBox
  52. android:id="@+id/checkBox1"
  53. android:layout_width="wrap_content"
  54. android:layout_height="wrap_content"
  55. android:text="显示密码" />
  56.  
  57. </TableRow>
  58.  
  59. <TableRow
  60. android:layout_width="wrap_content"
  61. android:layout_height="match_parent">
  62. <Button
  63. android:layout_width="wrap_content"
  64. android:layout_height="wrap_content"
  65. android:text="确定"
  66. android:id="@+id/ok"
  67. android:layout_column="1"
  68. android:layout_span="1" />
  69. <Button
  70. android:layout_width="wrap_content"
  71. android:layout_height="wrap_content"
  72. android:text="取消"
  73. android:id="@+id/cancel"
  74. android:layout_column="1" />
  75.  
  76. </TableRow>
  77.  
  78. </TableLayout>
  79.  
  80. </LinearLayout>
  1. package com.example.yanlei.mytk;
  2.  
  3. import android.os.Bundle;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.text.method.HideReturnsTransformationMethod;
  6. import android.text.method.PasswordTransformationMethod;
  7. import android.view.Menu;
  8. import android.view.MenuItem;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.CheckBox;
  12. import android.widget.CompoundButton;
  13. import android.widget.CompoundButton.OnCheckedChangeListener;
  14. import android.widget.TextView;
  15. import android.widget.Toast;
  16.  
  17. public class MainActivity extends AppCompatActivity {
  18.  
  19. private TextView passEdit;
  20. private TextView userNameEdit;
  21. private CheckBox checkBox1;
  22. private Button btnok;
  23. private Button btncancel;
  24.  
  25. @Override
  26. protected void onCreate(Bundle savedInstanceState) {
  27. super.onCreate(savedInstanceState);
  28. setContentView(R.layout.activity_main);
  29. passEdit = (TextView) findViewById(R.id.pass);
  30. userNameEdit = (TextView) findViewById(R.id.username);
  31. checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
  32. btnok = (Button) findViewById(R.id.ok);
  33. btncancel = (Button) findViewById(R.id.cancel);
  34.  
  35. btncancel.setOnClickListener(new ButtonexitClickListener());
  36. btnok.setOnClickListener(new ButtonokClickListener());
  37. checkBox1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
  38.  
  39. @Override
  40. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  41. // TODO Auto-generated method stub
  42. if (isChecked) {
  43. //如果选中,显示密码
  44. passEdit.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
  45. } else {
  46. //否则隐藏密码
  47. passEdit.setTransformationMethod(PasswordTransformationMethod.getInstance());
  48. }
  49.  
  50. }
  51. });
  52.  
  53. }
  54.  
  55. private class ButtonexitClickListener implements View.OnClickListener {
  56.  
  57. public void onClick(View v) {
  58. System.exit(0);
  59.  
  60. }
  61.  
  62. }
  63.  
  64. private class ButtonokClickListener implements View.OnClickListener {
  65.  
  66. public void onClick(View v) {
  67. String UserName = userNameEdit.getText().toString();
  68. String pass = passEdit.getText().toString();
  69. Toast toast;
  70.  
  71. if (UserName.equals("YL") && pass.equals("123")) {
  72. toast = Toast.makeText(getApplicationContext(), "密码正确" + UserName + ":" + pass, Toast.LENGTH_LONG);
  73.  
  74. } else {
  75. toast = Toast.makeText(getApplicationContext(), "密码错误" + UserName + ":" + pass, Toast.LENGTH_LONG);
  76. }
  77. toast.show();
  78.  
  79. }
  80.  
  81. }
  82.  
  83. @Override
  84. public boolean onCreateOptionsMenu(Menu menu) {
  85. // Inflate the menu; this adds items to the action bar if it is present.
  86. getMenuInflater().inflate(R.menu.menu_main, menu);
  87. return true;
  88. }
  89.  
  90. @Override
  91. public boolean onOptionsItemSelected(MenuItem item) {
  92. // Handle action bar item clicks here. The action bar will
  93. // automatically handle clicks on the Home/Up button, so long
  94. // as you specify a parent activity in AndroidManifest.xml.
  95. int id = item.getItemId();
  96.  
  97. //noinspection SimplifiableIfStatement
  98. if (id == R.id.action_settings) {
  99. return true;
  100. }
  101.  
  102. return super.onOptionsItemSelected(item);
  103. }
  104. }

优化界面

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="wrap_content"
  5. android:orientation="vertical"
  6. android:padding="3dip">
  7.  
  8. <!--0固定1可以扩展-->
  9.  
  10. <TableLayout
  11. android:layout_width="fill_parent"
  12. android:layout_height="wrap_content"
  13. android:numColumns="8"
  14. android:shrinkColumns="0"
  15. android:stretchColumns="1">
  16.  
  17. <TableRow
  18. android:layout_width="fill_parent"
  19. android:layout_height="wrap_content">
  20.  
  21. <TextView
  22. android:id="@+id/label"
  23. android:layout_width="wrap_content"
  24. android:layout_height="wrap_content"
  25. android:text="请输入用户名:" />
  26. <!-- 这个EditText放置在上边id为label的TextView的下边 -->
  27. <EditText
  28. android:id="@+id/username"
  29. android:layout_width="fill_parent"
  30. android:layout_height="wrap_content"
  31. android:layout_below="@id/label"
  32. android:background="@android:drawable/editbox_background" />
  33.  
  34. </TableRow>
  35.  
  36. <TableRow>
  37.  
  38. <TextView
  39. android:id="@+id/label1"
  40. android:layout_width="wrap_content"
  41. android:layout_height="wrap_content"
  42. android:text="密码:" />
  43. <!-- 这个EditText放置在上边id为label的TextView的下边 -->
  44. <EditText
  45. android:id="@+id/pass"
  46. android:layout_width="fill_parent"
  47. android:layout_height="wrap_content"
  48. android:layout_below="@id/label1"
  49. android:background="@android:drawable/editbox_background"
  50. android:inputType="textPassword" />
  51.  
  52. <CheckBox
  53. android:id="@+id/checkBox1"
  54. android:layout_width="wrap_content"
  55. android:layout_height="wrap_content"
  56. android:text="显示密码" />
  57.  
  58. </TableRow>
  59.  
  60. <TableRow
  61. android:layout_width="wrap_content"
  62. android:layout_height="match_parent">
  63.  
  64. </TableRow>
  65.  
  66. </TableLayout>
  67.  
  68. <LinearLayout
  69. android:layout_width="fill_parent"
  70. android:layout_height="wrap_content"
  71. android:orientation="horizontal"
  72. android:padding="5dip"
  73. android:gravity="right"
  74. android:weightSum="1">
  75.  
  76. <Button
  77. android:id="@+id/ok"
  78. android:layout_width="wrap_content"
  79. android:layout_height="wrap_content"
  80. android:layout_weight="0.20"
  81. android:text="确定"
  82. android:layout_marginRight="20dip" />
  83.  
  84. <Button
  85. android:id="@+id/cancel"
  86. android:layout_width="wrap_content"
  87. android:layout_height="wrap_content"
  88. android:text="取消"
  89. android:layout_weight="0.20"
  90. android:hint="退出"
  91.  
  92. android:clickable="true" />
  93. </LinearLayout>
  94. </LinearLayout>

=======================================================

又一个登陆界面

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical" >
  6. <TextView
  7. android:layout_width="match_parent"
  8. android:layout_height="wrap_content"
  9. android:textAlignment="center"
  10. android:text="用户登录界面"
  11.  
  12. android:autoText="false"
  13. android:gravity="center" />
  14.  
  15. <LinearLayout
  16. android:layout_width="match_parent"
  17. android:layout_height="wrap_content"
  18. android:orientation="horizontal" >
  19.  
  20. <TextView
  21. android:layout_width="wrap_content"
  22. android:layout_height="wrap_content"
  23. android:text="用户名 :" />
  24.  
  25. <EditText
  26. android:id="@+id/editText1"
  27. android:layout_width="match_parent"
  28. android:layout_height="wrap_content"
  29. android:hint="请输入用户名" />
  30. </LinearLayout>
  31.  
  32. <LinearLayout
  33. android:layout_width="match_parent"
  34. android:layout_height="wrap_content"
  35. android:orientation="horizontal" >
  36.  
  37. <TextView
  38. android:layout_width="wrap_content"
  39. android:layout_height="wrap_content"
  40.  
  41. android:text="密 码:" />
  42.  
  43. <EditText
  44. android:id="@+id/editText2"
  45. android:layout_width="match_parent"
  46. android:layout_height="wrap_content"
  47. android:hint="请输入密码"
  48. android:layout_weight="1"
  49. android:inputType="textPassword" />
  50.  
  51. <CheckBox
  52. android:layout_width="wrap_content"
  53. android:layout_height="wrap_content"
  54. android:text="显示密码"
  55.  
  56. android:id="@+id/checkBox" />
  57.  
  58. </LinearLayout>
  59.  
  60. <LinearLayout
  61. android:layout_width="match_parent"
  62. android:layout_height="wrap_content"
  63. android:orientation="horizontal" >
  64.  
  65. </LinearLayout>
  66.  
  67. <LinearLayout
  68. android:layout_width="match_parent"
  69. android:layout_height="wrap_content" >
  70.  
  71. <Button
  72. android:id="@+id/btn_confirm"
  73. android:layout_width="wrap_content"
  74. android:layout_height="wrap_content"
  75. android:layout_weight="1"
  76.  
  77. android:text="确认" />
  78.  
  79. <Button
  80. android:id="@+id/btn_back"
  81. android:layout_width="wrap_content"
  82. android:layout_height="wrap_content"
  83. android:layout_weight="1"
  84.  
  85. android:text="返回" />
  86. </LinearLayout>
  87.  
  88. <ImageView
  89. android:layout_width="wrap_content"
  90. android:layout_height="wrap_content"
  91.  
  92. android:id="@+id/imageView"
  93. android:layout_gravity="center_horizontal" />
  94.  
  95. </LinearLayout>

andriod 用户名和密码的更多相关文章

  1. TortoiseGit:记住用户名和密码

    1.背景: 我们在使用 tortoisegit 工具时会无可避免的经常性 pull 和 push,这时通常要输入用户名和密码,由于麻烦,就有人提出了记住用户名和密码的需求... ... 2.设置: [ ...

  2. git push不用重复输入用户名和密码(解决方案)

    每次git push都要输入用户名和密码,有点麻烦,就上网搜了下解决方案. 网上的解决方案有的讲得不清晰,逐个试了后,总结下两种有效的解决方案.   方案一: 1.在计算机安装盘(即一般为C盘)下找到 ...

  3. c#与JavaScript实现对用户名、密码进行RSA非对称加密

    博主最近手上这个项目呢(就是有上百个万恶的复杂excel需要解析的那个项目,参见博客:http://www.cnblogs.com/csqb-511612371/p/4885930.html),由于是 ...

  4. svn客户端重新设置用户名和密码

    在第一次使用TortoiseSVN从服务器CheckOut的时候,会要求输入用户名和密码,这时输入框下面有个选项是保存认证信息,如果选了这个选项,那么以后就不用每次都输入一遍用户名密码了. 不过,如果 ...

  5. 安装WAMP 及 修改MYSQL用户名 、 密码

    1,下载并安装WAMP 2,启动服务后,找到MYSQL--MYSQL console--弹出命令窗口(刚开始没有初始用户名跟密码,可直接回车执行) 3,首先输入 use mysq;l---然后修改用户 ...

  6. MySQL5.6忘记root用户名和密码

    首先我们要做的是关闭数据库,还好这个只是一个开发库,要是生产库的话使用另外一种方法修改root用户名和密码,我在另一篇文章有记载 然后我们跳过网络,跳过授权表,这个时候只有本机可以登录了,外部机器就不 ...

  7. svn清除已保存的用户名和密码

    在项目中使用SVN是必须的,我们一般将用户名和密码进行保存处理,这样做的好处在于每次都不用输入了,方便快捷.但是当我们想用另外一个svn账号时,这时候该怎么办呢,看下图,让提示框重新出来. 找到这个页 ...

  8. 系统无法开始服务器进程。请检查用户名和密码。 (Exception from HRESULT: 0x8000401A)

    开始-运行-cmd,输入aspnet_regiis.exe -i 重新注册iis 或者 出现以下错误:检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-0000 ...

  9. TortoiseGit 连接oschina不用每次输入用户名和密码的方法

    每次git clone 和push 都要输入用户名和密码.虽然安全,但在本机上每次都输有些麻烦,如何记住用户名和密码呢? 在网上看了各种方法,太杂,很多可能环境不一样,一直行不通.最后找到一种有效的方 ...

随机推荐

  1. drupal7 Views Bulk Operations (VBO)

    介绍 drupal通常用views制作列表,列表也应该能实现某些操作,例如删除.审批等,并且应该是批量进行的,VBO的存在就是为了实现views批量操作功能.事实上,drupal把操作统称为actio ...

  2. Android代码截屏

    本文来源:http://myhpu2008.iteye.com/blog/999779 这种方法应该只能对当前Activity本身进行截屏,因而你只能在你应用程序中参照该代码对其应用程序本身截屏. i ...

  3. php分页类代码带分页样式效果(转)

    php分页类代码,有漂亮的分页样式风格 时间:2016-03-16 09:16:03来源:网络 导读:不错的php分页类代码,将类文件与分页样式嵌入,实现php查询结果的精美分页,对研究php分页原理 ...

  4. base.js

    function $_id(id){return document.getElementById(id)};//$只定义为通过ID返回元素的功能 //-----------------------do ...

  5. Mac OS使用ll、la、l等ls的别名命令

    在linux下习惯使用ll.la.l等ls别名的童鞋到mac os可就郁闷了-- 其实只要在用户目录下建立一个脚本“.bash_profile”,并输入以下内容即可: alias ll='ls -al ...

  6. Windows上使用clang编译

    - 先自己从源代码 (http://llvm.org/releases/) 编译llvm和clang,或者直接安装clang for Windows - 测试过使用cygwin (https://cy ...

  7. storm分组模式

    Shuffle grouping: Tuples被随机分配到每一个bolt’s task,以便于每一个bolt’s task获得相同数量的tuples. Fields grouping: Stream ...

  8. Communication - 03.RILC

    RIL层的作用大体上就是将上层的命令转换成相应的AT指令,控制modem工作.生产modem的厂家有很多:Qualcomm, STE, Infineon... 不同的厂家都有各自的特点,当然也会有各自 ...

  9. gulp-notify处理报错----gulp系列(二)

    上一节,以less为例,入门了gulp,并为任务结构做了抽离. 前端们,gulp该用起来了,简单的demo入门——gulp系列(一) 本节学习下gulp-notify,官方这样解释的: gulp-no ...

  10. 开源一个基于天天团购的团购app

    可能大家都知道天天团购开源系统,一个做团购的开源项目很赞,前些日子做了基于天天团购系统做的团购客户端和移动端服务器!源代码放出,有了解的可以看看,希望收益! 先说服务器:app的服务器,基于天天团购的 ...