• 作业9


      1 ?xml version="1.0" encoding="utf-8"?>
      2 <RelativeLayout
      3     xmlns:android="http://schemas.android.com/apk/res/android"
      4     xmlns:app="http://schemas.android.com/apk/res-auto"
      5     xmlns:tools="http://schemas.android.com/tools"
      6     android:layout_width="match_parent"
      7     android:layout_height="match_parent"
      8     tools:context=".MainActivity"
      9     android:background="#ECE4E4"
     10 
     11 
     12     >
     13 
     14     <ImageView
     15         android:id="@+id/imageView"
     16         android:layout_width="80sp"
     17         android:layout_height="80sp"
     18         app:srcCompat="@drawable/1"
     19         android:layout_centerHorizontal="true"
     20         android:layout_marginTop="100sp"
     21         />
     22 <LinearLayout
     23         android:id="@+id/lzh"
     24         android:layout_width="match_parent"
     25         android:layout_height="wrap_content"
     26         android:layout_below="@+id/imageView"
     27         android:layout_marginTop="50dp"
     28         android:background="#FFFFFF"
     29         android:layout_marginLeft="20sp"
     30         android:layout_marginRight="20sp"
     31         android:orientation="horizontal">
     32 
     33         <TextView
     34             android:id="@+id/id"
     35             android:layout_width="wrap_content"
     36             android:layout_height="wrap_content"
     37             android:padding="15dp"
     38             android:text="账号:"
     39             android:textStyle="bold"
     40             android:textSize="20sp" />
     41 
     42         <EditText
     43             android:id="@+id/et1"
     44             android:layout_width="match_parent"
     45             android:layout_height="match_parent"
     46             android:background="#FFFFFF"
     47             android:padding="10dp">
     48 
     49         </EditText>
     50     </LinearLayout>
     51 
     52     <LinearLayout
     53         android:id="@+id/mm"
     54         android:layout_width="match_parent"
     55         android:layout_height="wrap_content"
     56         android:layout_below="@+id/lzh"
     57         android:layout_marginTop="50dp"
     58         android:background="#FFFFFF"
     59         android:layout_marginLeft="20sp"
     60         android:layout_marginRight="20sp"
     61         android:orientation="horizontal">
     62 
     63         <TextView
     64             android:id="@+id/pw"
     65             android:layout_width="wrap_content"
     66             android:layout_height="wrap_content"
     67             android:padding="15dp"
     68             android:text="密码:"
     69             android:textStyle="bold"
     70             android:textSize="20sp" />
     71         <EditText
     72             android:layout_width="match_parent"
     73             android:layout_height="match_parent"
     74             android:password="true"
     75             android:id="@+id/et2"
     76             android:padding="10dp"
     77             android:background="#FFFFFF">
     78 
     79         </EditText>
     80     </LinearLayout>
     81 
     82     <Button
     83         android:id="@+id/qr"
     84         android:layout_width="match_parent"
     85         android:layout_height="wrap_content"
     86         android:text="登录"
     87         android:textStyle="bold"
     88         android:textColor="#FFFFFF"
     89         android:textSize="30sp"
     90         android:background="#2196F3"
     91         android:layout_below="@+id/mm"
     92         android:layout_marginTop="60dp"
     93         android:layout_marginLeft="40dp"
     94         android:layout_marginRight="40dp"
     95 
     96         />
     97     <Button
     98         android:id="@+id/jz"
     99         android:layout_centerHorizontal="true"
    100         android:layout_below="@+id/qr"
    101         android:layout_marginTop="20sp"
    102         android:layout_width="wrap_content"
    103         android:layout_height="wrap_content"
    104         android:text="记住账号密码"
    105         android:onClick="jz"
    106         >
    107 
    108     </Button>
    109 
    110     <TextView
    111         android:id="@+id/tv"
    112         android:layout_width="wrap_content"
    113         android:layout_height="wrap_content"
    114         android:layout_below="@+id/qr"
    115         android:layout_centerHorizontal="true"
    116         android:layout_marginTop="50dp"
    117         android:text=""
    118         android:textColor="#59D683"
    119         android:textSize="20sp"
    120         android:textStyle="bold" />
    121 </RelativeLayout>
    package com.example.a9;
    
    import androidx.appcompat.app.AppCompatActivity;
    import android.content.SharedPreferences;
    import android.view.View;
    import android.widget.EditText;
    import android.widget.Toast;
    import android.os.Bundle;
    
    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            EditText zh=findViewById(R.id.et1);
            EditText mm=findViewById(R.id.et2);
            SharedPreferences s=getSharedPreferences("data",MODE_PRIVATE);
            String d_zh=s.getString("zh","");
            String d_mm=s.getString("mm","");
            Toast.makeText(this,d_zh+"密码"+d_mm,Toast.LENGTH_SHORT).show();
            zh.setText(d_zh);
            mm.setText(d_mm);
        }
    
        public void jz(View view) {
            EditText zh=findViewById(R.id.et1);
            EditText mm=findViewById(R.id.et2);
            String z=zh.getText().toString();
            String m=mm.getText().toString();
    
            SharedPreferences s=getSharedPreferences("data",MODE_PRIVATE);
            SharedPreferences.Editor editor=s.edit();
            editor.putString("zh",z);
            editor.putString("mm",m);
            editor.commit();
            Toast.makeText(this,"已经记住账号信息",Toast.LENGTH_SHORT).show();
    
        }
    }
    

      

  • 相关阅读:
    集合及特殊集合arrayList
    二维数组、多维数组
    一维数组

    for循坏的穷举与迭代,while、do while循环
    1.兔子生兔子问题2.打印菱形3.求100以内质数的和
    for循环嵌套
    复习题
    循环语句
    分支语句
  • 原文地址:https://www.cnblogs.com/96111314w/p/11961834.html
Copyright © 2020-2023  润新知