安卓作业—自动登录
来源:互联网 发布:2016百度最新算法3.0 编辑:程序博客网 时间:2024/04/29 22:45
<h2 style="margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">1.activity_main.xml</h2>
1.<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2. xmlns:tools="http://schemas.android.com/tools" 3. android:layout_width="match_parent" 4. android:layout_height="match_parent" 5. android:orientation="vertical" 6. android:background="@drawable/loginbg" 7. android:paddingBottom="@dimen/activity_vertical_margin" 8. android:paddingLeft="@dimen/activity_horizontal_margin" 9. android:paddingRight="@dimen/activity_horizontal_margin" 10. android:paddingTop="@dimen/activity_vertical_margin" 11. tools:context=".MainActivity" > 12. 13. <include layout="@layout/login_top"/> 14. <include layout="@layout/login_bottom"/>" 15. 16.</LinearLayout>
<h2 style="margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">2.login_top.xml</h2>
<pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/btnbg_roundcorner" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" > <TextView android:id="@+id/tvUsername" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="@string/tvName" android:textAppearance="?android:attr/textAppearanceMedium" /> <EditText android:id="@+id/etUsername" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignLeft="@+id/tvUsername" android:layout_below="@+id/tvUsername" android:background="@android:drawable/edit_text" android:ems="10" > <requestFocus /> </EditText> <TextView android:id="@+id/tvPassword" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/etUsername" android:layout_below="@+id/etUsername" android:text="@string/tvPassword" android:textAppearance="?android:attr/textAppearanceMedium" /> <EditText android:id="@+id/etPassword" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignLeft="@+id/tvPassword" android:layout_below="@+id/tvPassword" android:layout_marginTop="16dp" android:background="@android:drawable/edit_text" android:ems="10" android:inputType="textPassword" /> <Button android:id="@+id/btnLogin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@+id/etPassword" android:layout_below="@+id/etPassword" android:layout_marginTop="20dp" android:background="#FF72CAE1" android:text="@string/btnLogin" /> <CheckBox android:id="@+id/cbRememberPass" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/etPassword" android:layout_alignTop="@+id/btnLogin" android:text="记住密码" /> <CheckBox android:id="@+id/cbZddl" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/cbRememberPass" android:layout_below="@+id/cbRememberPass" android:text="自动登录" /> </RelativeLayout>
3.login_bottom.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/tvRegist" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="21dp" android:layout_marginTop="18dp" android:text="@string/tvRegister" android:autoLink="all" android:textColorLink="#FF0066CC" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginBottom="24dp" android:src="@drawable/panda" /> <ImageView android:id="@+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="28dp" android:src="@drawable/icon" /> </RelativeLayout>
4.chenggong.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="登陆成功" android:textAppearance="?android:attr/textAppearanceLarge" /> </LinearLayout>
5.btnbg_roundcorner.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#55FFFFFF"/> <corners android:radius="10dp"/> </shape>
6.loginbg.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#55FFFFFF"/> <corners android:radius="10dp"/> </shape>
7.strings.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">MiniTwitterSimulate</string> <string name="action_settings">Settings</string> <string name="hello_world">Hello world!</string> <string name="tvName">用户名</string> <string name="tvPassword">密码</string> <string name="btnLogin">登录</string> <string name="tvRegister">没有帐号? <a href="#" mce_href="#">注册</a></string> </resources>
<h2><span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">8.MainActivity.java</span></h2>
8.jhj.xml
1.package com.example.minitwittersimulate; 2. 3.import android.os.Bundle; 4.import android.app.Activity; 5.import android.app.backup.SharedPreferencesBackupHelper; 6.import android.content.Intent; 7.import android.content.SharedPreferences; 8.import android.content.SharedPreferences.Editor; 9.import android.view.Menu; 10.import android.view.View; 11.import android.view.View.OnClickListener; 12.import android.view.Window; 13.import android.widget.Button; 14.import android.widget.CheckBox; 15.import android.widget.EditText; 16.import android.widget.Toast; 17. 18.public class MainActivity extends Activity { 19. private EditText yhm; 20. private EditText mima; 21. private CheckBox jzmm; 22. private CheckBox zddl; 23. private Button dl; 24. private SharedPreferences sharedPreferences = null; 25. 26. @Override 27. protected void onCreate(Bundle savedInstanceState) { 28. super.onCreate(savedInstanceState); 29. requestWindowFeature(Window.FEATURE_NO_TITLE); 30. setContentView(R.layout.activity_main); 31. yhm = (EditText)findViewById(R.id.etUsername); 32. mima = (EditText)findViewById(R.id.etPassword); 33. jzmm = (CheckBox)findViewById(R.id.cbRememberPass); 34. zddl = (CheckBox) findViewById(R.id.cbZddl); 35. dl = (Button)findViewById(R.id.btnLogin); 36. setListener(); 37. } 38. private void setListener() { 39. if(zddl.isChecked()){ 40. if("jhj".equals(yhm.getText().toString())&& "123456".equals(mima.getText().toString())){ 41. Intent i = new Intent(MainActivity.this,chenggong.class); 42. startActivity(i); 43. }else{ 44. Toast.makeText(getApplicationContext(),"应户名或密码错误", Toast.LENGTH_SHORT).show(); 45. } 46. }else{ 47. dl.setOnClickListener(new OnClickListener() { 48. 49. @Override 50. public void onClick(View v) { 51. // TODO Auto-generated method stub 52. if("jhj".equals(yhm.getText().toString())&& "123456".equals(mima.getText().toString())){ 53. if(jzmm.isChecked()){ 54. sharedPreferences=getSharedPreferences("data",MODE_PRIVATE); 55. Editor edit = sharedPreferences.edit(); 56. edit.putBoolean("isKeep", true); 57. edit.putString("yhm",yhm.getText().toString()); 58. edit.putString("mima", mima.getText().toString()); 59. edit.commit(); 60. }else{ 61. SharedPreferences sharedPreferences = getSharedPreferences("data",MODE_PRIVATE); 62. Editor edit = sharedPreferences.edit(); 63. edit.putBoolean("isKeep", false); 64. edit.putString("yhm",""); 65. edit.putString("mima",""); 66. edit.commit(); 67. } 68. Intent i = new Intent(MainActivity.this,chenggong.class); 69. startActivity(i); 70. }else{ 71. Toast.makeText(getApplicationContext(),"应户名或密码错误", Toast.LENGTH_SHORT).show(); 72. } 73. } 74. });} 75. 76. } 77. protected void onResume(){ 78. super.onResume(); 79. getData(); 80. } 81. 82. private void getData() { 83. sharedPreferences = getSharedPreferences("data",MODE_PRIVATE); 84. if(sharedPreferences.getBoolean("isKeep",false)){ 85. yhm.setText(sharedPreferences.getString("yhm","")); 86. mima.setText(sharedPreferences.getString("mima","")); 87. } 88. else{ 89. yhm.setText(""); 90. mima.setText(""); 91. } 92. 93. } 94. @Override 95. public boolean onCreateOptionsMenu(Menu menu) { 96. // Inflate the menu; this adds items to the action bar if it is present. 97. getMenuInflater().inflate(R.menu.main, menu); 98. return true; 99. } 100. 101.}
9.chenggong.java
package com.example.minitwittersimulate; import android.app.Activity; import android.os.Bundle; public class chenggong extends Activity{ protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.chenggong); } }
0 0
- 安卓作业—自动登录
- 安卓自动登录
- 安卓开发—帐号登录,自动登录功能
- 安卓自动登录demo——SharedPreferences的应用
- 安卓记住密码和自动登录
- 安卓记住密码和自动登录
- 安卓作业—词典
- 华东理工大学校园网自动登录——安卓——Windows
- 安卓记住密码自动登录的实现
- 安卓作业—显示图片
- 安卓作业
- 安卓作业
- 安卓作业
- 安卓作业--第一篇
- 安卓作业--第二篇
- 安卓作业--第三篇
- 安卓作业--第四篇
- 安卓登陆框记住密码和自动登录的实现
- 2015网络安全大会-上
- 打包静态库和动态库
- 自定义View初体验(一)
- 手机移动端web 禁止手机返回功能的最好方法,虽然很变态,但是很有效.
- override 和 overload的区别(较全面)
- 安卓作业—自动登录
- 【近代史】抗日民主根据地的建设
- PL/SQL 命名规范
- 欢迎使用CSDN-markdown编辑器
- android 背景音乐的实现
- 弹出一个不带地址栏、工具栏的IE非模态窗口
- acm 推荐题
- 通过startActivityForResult来调用Activity
- HashMap实现原理分析