目录
1.MainActivity
代码如下(示例):
package com.example.administrator.myapplication;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private EditText accountEdit;
private EditText pswdEdit;
private Button btnLogin;
private CheckBox rememberPass;
private SharedPreferences pref;
private SharedPreferences.Editor editor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pref = PreferenceManager.getDefaultSharedPreferences(this);
accountEdit = (EditText)findViewById(R.id.accout);
pswdEdit = (EditText)findViewById(R.id.pswd);
btnLogin = (Button)findViewById(R.id.btn_login);
rememberPass = (CheckBox)findViewById(R.id.cb_remember);
boolean isRemember = pref.getBoolean("remem_pswd",false);
if(isRemember){
String accout = pref.getString("account","");
String passw = pref.getString("passw","");
accountEdit.setText(accout);
pswdEdit.setText(passw);
rememberPass.setChecked(true);
}
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String account = accountEdit.getText().toString().trim();
String password = pswdEdit.getText().toString().trim();
if(account.equals("admin")&&password.equals("123")){
editor = pref.edit();
if(rememberPass.isChecked()){
editor.putBoolean("remem_pswd",true);
editor.putString("account",account);
editor.putString("passw",password);
}else{
editor.clear();
}
editor.apply();
Toast.makeText(getApplicationContext(),"登录成功!",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(),"用户密码错误!",Toast.LENGTH_SHORT).show();
}
}
});
}
}
2.activity_main.xml
代码如下(示例):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="60dp">
<TextView
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textSize="18sp"
android:text="Account:"/>
<EditText
android:id="@+id/accout"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="60dp">
<TextView
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textSize="18sp"
android:text="Password:"/>
<EditText
android:id="@+id/pswd"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/cb_remember"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="Remember password" />
</LinearLayout>
<Button
android:id="@+id/btn_login"
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Login" />
</LinearLayout>
总结
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。