最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實現(xiàn)登錄注冊界面框架

 更新時間:2021年09月02日 08:55:34   作者:凡人不會死  
這篇文章主要介紹了Android實現(xiàn)登錄注冊界面的框架,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下

小項目框架

今天用QQ的時候想到了,不如用android studio 做一個類似于這樣的登錄軟件。當然QQ的實現(xiàn)的功能特別復雜,UI界面也很多,不是單純的一時新奇就可以做出來的。就是簡單的實現(xiàn)了一些功能,做了三個界面;1.登錄界面。2.注冊界面。3.登陸后的界面。

功能描述

登錄按鈕------按鈕實現(xiàn)跳轉到下一個界面,并且判斷輸入的賬號、密碼是否符合規(guī)則(不為空),提示,登陸成功或失敗
注冊按鈕------按鈕實現(xiàn)跳轉到注冊界面

登錄界面

在這里插入圖片描述

main_activity.xml

 <LinearLayout
        android:id="@+id/number"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/iv"
        android:layout_centerVertical="true"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="15dp"
        android:background="#ffffff">
        <TextView
            android:id="@+id/tv_number"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="賬號"
            android:textColor="#000"
            android:textSize="20dp" />
        <EditText
            android:id="@+id/et_username"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:background="@null"
            android:padding="10dp" />
    </LinearLayout>
    <LinearLayout
        android:id="@+id/password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/number"
        android:layout_centerVertical="true"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="#ffffff">
        <TextView
            android:id="@+id/tv_password"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="密碼"
            android:textSize="20dp"
            android:textColor="#000" />
        <EditText
            android:id="@+id/et_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_toRightOf="@id/tv_password"
            android:background="@null"
            android:inputType="textPassword"
            android:padding="10dp" />
    </LinearLayout>
    <Button
        android:id="@+id/button_login"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/password"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="60dp"
        android:background="#3c8dc4"
        android:text="登錄"
        android:textColor="#ffffff"
        android:textSize="20dp" />
    <Button
        android:id="@+id/button_register"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/button_login"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="30dp"
        android:background="#b7585556"
        android:text="注冊"
        android:textColor="#ffffff"
        android:textSize="20dp" />

    <CheckBox
        android:checked="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="記住密碼"
        android:id="@+id/checkBox"
        android:layout_below="@+id/password"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="5dp"/>

注冊界面
確定注冊------按鈕實現(xiàn)注冊,判斷以上四個注冊信息是否符合規(guī)則,判斷兩次輸入密碼是否一樣,并且不為空。并且顯示提示信息
返回登錄------按鈕實現(xiàn)跳轉到剛才的登錄界面

在這里插入圖片描述

main_activity.java

public class MainActivity extends AppCompatActivity {
    private EditText et_username;
    private EditText et_password;
    private EditText et_password2;
    private EditText et_mail;
    private Button btn_login;
    private Button btn_register;
    private CheckBox checkbox;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Map<String, String> userInfo = SaveInfo.getSaveInformation(this);
        if (userInfo != null) {
            et_username.setText(userInfo.get("username"));
            et_password.setText(userInfo.get("password"));
        }
        et_username =(EditText) findViewById(R.id.et_username);
        et_password =(EditText) findViewById(R.id.et_password);
        et_password2 =(EditText) findViewById(R.id.reg_password2);
        et_mail = (EditText) findViewById(R.id.reg_mail);
        checkbox = (CheckBox) findViewById(R.id.checkBox);
        btn_login =(Button) findViewById(R.id.button_login);
        btn_register =(Button) findViewById(R.id.button_register);
        btn_login.setOnClickListener(new MyButton());
        btn_register.setOnClickListener(new MyButton());
                    }
    public  class MyButton implements View.OnClickListener{
        @Override
        public void onClick(View view){
            String username =et_username.getText().toString().trim();
            String password =et_password.getText().toString().trim();
            switch (view.getId()) {
                //當點擊登錄按鈕時
                case R.id.button_login:
                    if(TextUtils.isEmpty(username) || TextUtils.isEmpty(password)){
                        Toast.makeText(MainActivity.this,"密碼或賬號不能為空",Toast.LENGTH_SHORT).show();
                    } else {
                        if(checkbox.isChecked()){
                            //保存密碼的操作
                        }
                        Toast.makeText(MainActivity.this,"登錄成功",Toast.LENGTH_SHORT).show();
                            Intent intent = new Intent(MainActivity.this, LoginActivity.class);
                            startActivity(intent);
                        }
                    break;
                //當點擊注冊按鈕事件時
                case R.id.button_register:
                    Intent intent = new Intent(MainActivity.this,RegisterActivity.class);
                    startActivity(intent);
                    break;

            }
        }
    }
                }

register_activity

    <TextView
        android:layout_marginTop="60dp"
        android:id="@+id/reg_number1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="賬號:"
        android:textColor="#000"
        android:textSize="20dp" />
    <EditText
        android:layout_alignBottom="@+id/reg_number1"
        android:layout_toRightOf="@+id/reg_number1"
        android:id="@+id/reg_username"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp" />
    <TextView
        android:id="@+id/reg_number2"
        android:layout_marginTop="5dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/reg_number1"
        android:padding="10dp"
        android:text="密碼:"
        android:textColor="#000"
        android:textSize="20dp" />
    <EditText
        android:layout_alignBottom="@id/reg_number2"
        android:layout_toRightOf="@+id/reg_number2"
        android:id="@+id/reg_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp" />
    <TextView
        android:id="@+id/reg_number3"
        android:layout_marginTop="5dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/reg_number2"
        android:padding="10dp"
        android:text="密碼:"
        android:textColor="#000"
        android:textSize="20dp" />
    <EditText
        android:layout_alignBottom="@id/reg_number3"
        android:layout_toRightOf="@+id/reg_number3"
        android:id="@+id/reg_password2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp" />
    <TextView
        android:id="@+id/reg_number4"
        android:layout_marginTop="5dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/reg_number3"
        android:padding="10dp"
        android:text="郵箱:"
        android:textColor="#000"
        android:textSize="20dp" />
    <EditText
        android:layout_alignBottom="@id/reg_number4"
        android:layout_toRightOf="@+id/reg_number4"
        android:id="@+id/reg_mail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="確定注冊"
        android:background="#74e674"
        android:id="@+id/reg_btn_sure"
        android:layout_marginTop="38dp"
        android:layout_below="@+id/reg_mail"
        android:layout_marginLeft="50dp" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="返回登錄"
        android:background="#f27758"
        android:id="@+id/reg_btn_login"
        android:layout_alignBottom="@id/reg_btn_sure"
        android:layout_toRightOf="@id/reg_btn_sure"
        android:layout_marginLeft="60dp"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="賬號注冊"
        android:textSize="30dp"
        android:layout_marginTop="5dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>

registeractivity.java

public class RegisterActivity extends AppCompatActivity {
    private EditText reg_username;
    private EditText reg_password;
    private EditText reg_password2;
    private EditText reg_mail;
    private Button reg_btn_sure;
    private Button reg_btn_login;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        reg_username = (EditText) findViewById(R.id.reg_username);
        reg_password = (EditText) findViewById(R.id.reg_password);
        reg_password2 = (EditText) findViewById(R.id.reg_password2);
        reg_mail = (EditText) findViewById(R.id.reg_mail);
        reg_btn_sure = (Button) findViewById(R.id.reg_btn_sure);
        reg_btn_login = (Button) findViewById(R.id.reg_btn_login);
        reg_btn_sure.setOnClickListener(new RegisterButton());
        reg_btn_login.setOnClickListener(new RegisterButton());
    }

    public class RegisterButton implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            String username = reg_username.getText().toString().trim();
            String password = reg_password.getText().toString().trim();
            String password2 = reg_password2.getText().toString().trim();
            String mail = reg_mail.getText().toString().trim();
            switch (v.getId()) {
                //注冊開始,判斷注冊條件
                case R.id.reg_btn_sure:
                    if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password) || TextUtils.isEmpty(password2) || TextUtils.isEmpty(mail)) {
                        Toast.makeText(RegisterActivity.this, "各項均不能為空", Toast.LENGTH_SHORT).show();
                    } else {
                        if (TextUtils.equals(password, password2)) {
                            //執(zhí)行注冊操作
                            SaveInfo.SaveInformation(RegisterActivity.this,username,password,password2,mail);
                            Toast.makeText(RegisterActivity.this,"注冊成功,請返回登錄",Toast.LENGTH_SHORT).show();
                        } else {
                            Toast.makeText(RegisterActivity.this, "兩次輸入的密碼不一樣", Toast.LENGTH_SHORT).show();
                        }
                    }
                        break;
                        case R.id.reg_btn_login:
                            Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
                            startActivity(intent);
                            break;

                    }
            }
        }
    }

登錄成功界面創(chuàng)建一個布局文件就可以了,寫上你想要的東西,我自己就是創(chuàng)建了一個布局,什么都沒有,所以就在這里不寫了
在這里因為要做一個保存操作,所以創(chuàng)建了一個java工具類,其中定義了兩個方法,一個保存登錄名和密碼,一個負責調用保存的登錄名和密碼
saveinfo

public class SaveInfo {
    public static boolean SaveInformation(Context context, String username, String password, String password2, String mail) {
        try {
            FileOutputStream fos = context.openFileOutput("data.txt", Context.MODE_APPEND);
            fos.write(("用戶名:" + username + " 密碼:" + password + "郵箱:" + mail).getBytes());
            fos.close();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public static Map<String, String> getSaveInformation(Context context) {
        try {
            FileInputStream fis = context.openFileInput("data.txt");
            BufferedReader br = new BufferedReader(new InputStreamReader(fis));
            String str = br.readLine();
            String[] infos = str.split("用戶名:"+"密碼:"+"郵箱:");
            Map<String, String> map = new HashMap<String, String>();
            map.put("username", infos[0]);
            map.put("password", infos[1]);
            fis.close();
            return map;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

示例圖片

注冊賬號

在這里插入圖片描述

在這里插入圖片描述

在這里插入圖片描述

在這里插入圖片描述

【評論需要解決的問題或者文章中的不恰當的地方,接受改正】

到此這篇關于Android實現(xiàn)登錄注冊界面框架的文章就介紹到這了,更多相關Android登錄注冊框架內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論

洪泽县| 怀仁县| 周宁县| 连州市| 天津市| 津南区| 谢通门县| 额济纳旗| 永年县| 伽师县| 察哈| 陇川县| 那曲县| 南投市| 稷山县| 屯留县| 六枝特区| 新源县| 闽侯县| 安多县| 鄂伦春自治旗| 怀仁县| 潮州市| 唐海县| 新密市| 崇礼县| 永川市| 龙江县| 贡山| 遂宁市| 娄底市| 新龙县| 大同县| 巴南区| 四平市| 永丰县| 梅州市| 香港 | 茶陵县| 紫阳县| 酒泉市|