zoukankan      html  css  js  c++  java
  • 第八次作业

    <?xml version="1.0" encoding="utf-8"?>
    <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=".MainActivity">
    
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="50dp"
            android:src="@drawable/qq" />
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="30dp">
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="账号:"
                android:textSize="30sp" />
    
            <EditText
                android:id="@+id/etName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="请输入账号"
                android:textSize="30sp" />
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp">
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="密码:"
                android:textSize="30sp" />
    
            <EditText
                android:id="@+id/etPassword"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="请输入密码"
                android:inputType="textPassword"
                android:textSize="30sp" />
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="30dp">
    
            <CheckBox
                android:id="@+id/cbRemember"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:text="记住密码"
                android:textSize="20sp" />
    
            <Button
                android:id="@+id/btnLogin"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:onClick="btnLogin"
                android:text="登录"
                android:textSize="20sp" />
    
            <Button
                android:id="@+id/btnExit"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:text="取消"
                android:textSize="20sp" />
    
        </LinearLayout>
    
    
    </LinearLayout>
        复制代码
        复制代码
        package com.example.minkexin;
    
        import android.app.Notification;
        import android.content.SharedPreferences;
        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 {
    
        EditText userid;  //声明控件
        EditText lipassword;
        Button login;
        private CheckBox cbRemember;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        userid=(EditText)findViewById(R.id.userid); //控件的初始化
        lipassword=(EditText)findViewById(R.id.lipassword);
        login=(Button)findViewById(R.id.login);   //监听
        cbRemember = findViewById(R.id.cbRemember);
        SharedPreferences sp = getSharedPreferences("date", MODE_PRIVATE);
        userid.setText(sp.getString("name", ""));
        lipassword.setText(sp.getString("password", ""));
    
    
    
        login.setOnClickListener(new View.OnClickListener() {
        @Override   //方法的调用
        public void onClick(View view) {
    
        if ("admin".equals(userid.getText().toString())&&"admin".equals(lipassword.getText().toString())) {
        if (cbRemember.isChecked()) {
        SharedPreferences sp = getSharedPreferences("date", MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("name", userid.getText().toString());
        editor.putString("password", lipassword.getText().toString());
        editor.commit();
        Toast t1 = Toast.makeText(getApplicationContext(), "登录成功", Toast.LENGTH_SHORT);
        t1.show();
        } else {
        SharedPreferences sp = getSharedPreferences("date", MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("name", "");
        editor.putString("password", "");
        editor.commit();
        Toast t3 = Toast.makeText(getApplicationContext(), "登录成功,保存失败", Toast.LENGTH_SHORT);
        t3.show();
    
        }
        }
        else {
        Toast t2 = Toast.makeText(getApplicationContext(), "登录失败", Toast.LENGTH_SHORT);
        t2.show();
        userid.setText("");
        lipassword.setText("");
        }
        }
        });
        }
        }

  • 相关阅读:
    Angular Universal 学习笔记
    SAP Spartacus 如何获得当前渲染页面的 CMS 元数据
    Angular 服务器端渲染的学习笔记(二)
    Angular 服务器端渲染的学习笔记(一)
    第三方外部 Saas提供商如何跟使用 SAP 系统的客户进行对接接口集成
    如何从 SAP Spartacus Product Detail 页面,找到其 Angular 实现 Component 的位置
    具备自动刷新功能的 SAP ABAP ALV 报表
    C++学习目录
    c--条件编译
    c--文件读写--二进制
  • 原文地址:https://www.cnblogs.com/zf08/p/11837464.html
Copyright © 2011-2022 走看看