用户登录记录密码
来源:互联网 发布:布谷鸟软件 编辑:程序博客网 时间:2024/05/18 00:07
AndroidManifest.Java
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.edu.bzu.case_login"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".LoginActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity"></activity> </application></manifest>
LoginActivitypackage cn.edu.bzu.case_login;import android.content.Context;import android.content.Intent;import android.content.SharedPreferences;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.CheckBox;import android.widget.EditText;import android.widget.Toast;public class LoginActivity extends AppCompatActivity { private EditText etName; private EditText etPassword; private SharedPreferences sharedPreferences ; private CheckBox cbIsRemeberPass; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); initViews(); sharedPreferences= getSharedPreferences("rememberpassword", Context.MODE_PRIVATE); boolean isRemeber= sharedPreferences.getBoolean("rememberpassword",false); if (isRemeber){ String name=sharedPreferences.getString("name",""); String password=sharedPreferences.getString("password",""); etName.setText(name); etPassword.setText(password); cbIsRemeberPass.setChecked(true); } } private void initViews() { etName=(EditText) findViewById(R.id.etName); etPassword=(EditText)findViewById(R.id.etPassword); cbIsRemeberPass=(CheckBox)findViewById(R.id.cbIsRememberPass); } public void login(View view){ String name=etName.getText().toString(); String password=etPassword.getText().toString(); if ("admain".equals(name)&&"123456".equals(password)){ SharedPreferences.Editor editor=sharedPreferences.edit(); if (cbIsRemeberPass.isChecked()){ editor.putBoolean("remeberpassword",true); editor.putString("name",name); editor.putString("password",password); }else { editor.clear(); } editor.commit(); Intent intent=new Intent(this,MainActivity.class); startActivity(intent); finish(); }else { Toast.makeText(this,"账号或密码有误",Toast.LENGTH_LONG.show()); } }}
MainActivitypackage cn.edu.bzu.case_login;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }}
activity_login.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/activity_login" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:background="@drawable/loginbg" tools:context="cn.edu.bzu.case_login.LoginActivity"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" app:srcCompat="@drawable/deer" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:layout_marginBottom="20dp" android:id="@+id/imageView" /></RelativeLayout>activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="cn.edu.bzu.case_login.MainActivity"> <TextView android:text="Welcome you" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:textSize="40sp" android:layout_marginTop="263dp" android:id="@+id/textView" /></RelativeLayout>login_top.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="@dimen/activity_horizontal_margin" android:background="@drawable/logintop_roundbg"> <EditText android:id="@+id/etName" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:drawable/edit_text" android:drawableLeft="@drawable/icon_user" android:drawablePadding="10dp" android:ems="10" android:hint="@string/etName"> <requestFocus /> </EditText> <EditText android:id="@+id/etPassword" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/etName" android:background="@android:drawable/edit_text" android:drawableLeft="@drawable/icon_pass" android:drawablePadding="10dp" android:ems="10" android:hint="@string/etPass" android:inputType="textPassword"> <requestFocus /> </EditText> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/etPassword"> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/btn_select" android:text="@string/btnLogin" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:layout_marginLeft="10dp" android:background="@drawable/btn_select" android:text="@string/btnRegister" /> </LinearLayout></RelativeLayout>结果运行图:
0 0
- 用户登录记录密码
- 用户登录和记录密码
- android 用户登录及记录密码功能
- 用户登录记住密码
- 用户登录记住密码
- 用户登录记住密码
- 用户登录记住密码
- 用户登录记住密码
- 用户登录记住密码
- 用户登录记住密码
- 用户登录记住密码
- 用户登录记住密码
- 用户登录记住密码
- 用户登录记住密码
- 用户登录记住密码
- 用户登录记住密码
- 用户登录记住密码
- 用户登录记住密码
- 排序算法
- 异常
- PHPStorm 提示502 Bad Gateway
- 如何在ROS中使用PCL—数据格式(1)
- PCL中点云数据格式之间的转化
- 用户登录记录密码
- 文件读写-流的操作
- 有关eclipse选项框乱码问题
- 浅谈用户及用户组
- PCL特征点与配准(1)
- cv_bridge中的编码模式与实现
- Selenium在Firefox中踩过的
- PCL常见错误集锦
- redis常用命令