zoukankan      html  css  js  c++  java
  • 安卓用户名密码操作及虚拟机问题

    今日所学:

    记住用户名和登录密码

    用adb查看保存文件内容

    如何使用adb 如何安装adb-百度经验

    遇到的问题:

    用adb查看文件时,没有权限访问data文件

    出现原因:google play虚拟机没有root权限

    解决办法:

    用google API的虚拟机

    相关博客:adb shell中提示Permission denied - 简书

    关于/system/bin/sh: su: not found的解决办法(安卓模拟器运行) - 程序员大本营

    成果截图:

    代码:

    MainActivity.java

    复制代码
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.content.Context;
    import android.content.SharedPreferences;
    import android.os.Bundle;
    import android.text.Editable;
    import android.text.TextWatcher;
    import android.util.Log;
    import android.widget.CheckBox;
    import android.widget.CompoundButton;
    import android.widget.EditText;
    
    public class MainActivity extends AppCompatActivity {
    
        private EditText mEtPhone;
        private EditText mEtPasswd;
        private CheckBox mPsd;
        private String SP_PHONE="sp_phone";
        private String SP_PASSWD="sp_passwd";
        private SharedPreferences sharedPreferences;
        private String SP_IS_REMEMBER="sp_is_remember";
        private boolean isCheck=false;
        private String TAG="MainActivity";
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            initUI();
            initData();
        }
    
        private void initData() {
            if(sharedPreferences==null){
                sharedPreferences=getApplicationContext().getSharedPreferences("config", Context.MODE_PRIVATE);
            }
            mEtPhone.setText(sharedPreferences.getString(SP_PHONE,""));
            mEtPasswd.setText(sharedPreferences.getString(SP_PASSWD,""));
            isCheck=sharedPreferences.getBoolean(SP_IS_REMEMBER,false);
            Log.i(TAG,"测试:"+isCheck);
            mPsd.setChecked(isCheck);
        }
    
        private void initUI() {
            mEtPhone=findViewById(R.id.et_phone);
            mEtPhone.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    
                }
    
                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
    
                }
    
                @Override
                public void afterTextChanged(Editable s) {
                    if(isCheck){
                        if(sharedPreferences==null){
                            sharedPreferences=getApplicationContext().getSharedPreferences("config", Context.MODE_PRIVATE);
                        }
                        SharedPreferences.Editor edit=sharedPreferences.edit();
                        edit. putString(SP_PHONE,mEtPhone.getText().toString());
                        edit.commit();
                    }
    
                }
            });
            mEtPasswd=findViewById(R.id.et_passwd);
            mEtPasswd.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    
                }
    
                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
    
                }
    
                @Override
                public void afterTextChanged(Editable s) {
                    if(isCheck){
                        if(sharedPreferences==null){
                            sharedPreferences=getApplicationContext().getSharedPreferences("config", Context.MODE_PRIVATE);
                        }
                        SharedPreferences.Editor edit=sharedPreferences.edit();
                        edit.putString(SP_PASSWD,mEtPasswd.getText().toString());
                        edit.commit();
                    }
    
                }
            });
            mPsd=findViewById(R.id.cb_remember_psd);
            mPsd.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    Log.d(TAG,"状态为:"+isChecked);
                    isCheck=isChecked;
    
                    if(sharedPreferences==null){
                        sharedPreferences=getApplicationContext().getSharedPreferences("config", Context.MODE_PRIVATE);
                    }
                    SharedPreferences.Editor edit=sharedPreferences.edit();
                    if(isChecked){
                        edit. putString(SP_PHONE,mEtPhone.getText().toString());
                        edit.putString(SP_PASSWD,mEtPasswd.getText().toString());
                    }
                    edit.putBoolean(SP_IS_REMEMBER,isChecked);
                    edit.commit();
                }
            });
    
        }
    }
    复制代码

    activity_main.xml

    复制代码
      
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context=".MainActivity">
    
        <EditText
            android:id="@+id/et_phone"
            android:inputType="phone"
            android:hint="电话"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
        <EditText
            android:id="@+id/et_passwd"
            android:inputType="textPassword"
            android:hint="密码"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
        <CheckBox
            android:id="@+id/cb_remember_psd"
            android:text="记住密码"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        <Button
            android:text="登录"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    
    </LinearLayout>
    复制代码
  • 相关阅读:
    二、Python基础练习
    代码测试服同步到生产服务器
    支付宝网站支付 异步验签成功 同步验签失败
    最近机房让整改的漏洞 设置cookie httponly X-Frame-Options头未设置
    连连支付,或微信或支付宝支付,商品名称最后一个字乱码,php解决
    ci 框架新手使用
    php制作公司五章,圆形印章和椭圆形印章,正方形印章,圆角正方形印章,圆角框
    Libreoffice php使用命令行office转pdf,pdf转图片
    后台返回数据回显,使用js控制默认选中复选框和下拉框
    Nginx日志按日期切割详解(按天切割)
  • 原文地址:https://www.cnblogs.com/jz-no-bug/p/14907655.html
Copyright © 2011-2022 走看看