AS简单的登陆界面

先设计好界面


   //设置背景图片

    

       //默认水平分布

           

             //输入类型
    

    

        

        
    

    

        

MainActivity

package com.example.organic_farm_production_management;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";
    private static final String KEY_INDEX = "index";
    private EditText musername;
    private EditText muserpassword;
    private Button mLogin;
    private Button mRegist;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        musername = (EditText) findViewById(R.id.username) ;
        muserpassword = (EditText) findViewById(R.id.userpassword);
        mLogin = (Button) findViewById(R.id.Login);
        mRegist = (Button) findViewById(R.id.Regist);

        mLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//以下是连接数据库
//UserService是有增删改查的一个类,记得换成自己的
                String name = musername.getText().toString();
                if (name.length() == 0)
                {
                    Toast.makeText(MainActivity.this,R.string.nousername,Toast.LENGTH_SHORT).show();
                }else{
                    String password = muserpassword.getText().toString();
                    UserService userService = new UserService(MainActivity.this);
                    boolean flag = userService.login(name,password);
                    if (flag == false)
                    {
                        Toast.makeText(MainActivity.this,R.string.errorlogin,Toast.LENGTH_SHORT).show();
                    }
                    if (flag == true)
                    {
                        Intent intent = new Intent(MainActivity.this,Glebe_Manage_Activity.class);
                        startActivity(intent);
                    }
                }

            }
        });
        mRegist.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,RegistActivity.class);
                startActivity(intent);
            }

        });


    }
}

结果图

AS简单的登陆界面_第1张图片

你可能感兴趣的:(Android)