京东登录

//布局

<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="qubentao.com.zhoukaosanmini.MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="登 陆"
            android:textSize="25sp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:id="@+id/tv_login"/>
        <View
            android:layout_width="120dp"
            android:layout_height="5dp"
            android:background="#C71622"
            android:layout_below="@id/tv_login"
            android:layout_centerInParent="true"/>
    RelativeLayout>
    <ImageView
        android:layout_width="280dp"
        android:layout_height="wrap_content"
        android:src="@drawable/jd"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="10dp"/>

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/txip_username"
        android:padding="10dp"
        >
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/tv_username"
            android:hint="账号"/>
    android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/txip_passworld"
        android:padding="10dp"
        >
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/tx_passworld"
            android:hint=""/>
    android.support.design.widget.TextInputLayout>

    <Button
        android:id="@+id/bt_login"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:background="#C71622"
        android:text="登 陆"
        android:textColor="#fff"
        android:textSize="25sp"/>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:id="@+id/tv_registe_refactor"
            android:text="密码修改"
            android:textSize="18sp"
            android:paddingLeft="10dp"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/tv_registe_login"
            android:text="注册新用户"
            android:textSize="18sp"
            android:layout_alignParentRight="true"
            android:paddingRight="10dp"/>
    RelativeLayout>


    <ImageView
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:src="@drawable/mqq"
        android:layout_marginTop="30dp"
        android:layout_marginLeft="265dp"
        />

LinearLayout>

//activity

public class MainActivity extends AppCompatActivity implements DengAct{

    @butterknife.BindView(R.id.tv_login)
    TextView tvLogin;
    @butterknife.BindView(R.id.tv_username)
    EditText tvUsername;
    @butterknife.BindView(R.id.txip_username)
    TextInputLayout txipUsername;
    @butterknife.BindView(R.id.tx_passworld)
    EditText txPassworld;
    @butterknife.BindView(R.id.txip_passworld)
    TextInputLayout txipPassworld;
    @butterknife.BindView(R.id.bt_login)
    Button btLogin;
    @butterknife.BindView(R.id.tv_registe_login)
    TextView tvRegisteLogin;
    @butterknife.BindView(R.id.tv_registe_refactor)
    TextView tvRegisteRefactor;
    private DengPresenter dengPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        butterknife.ButterKnife.bind(this);
        tvUsername.setHint("手机号/邮箱/用户名");
        txPassworld.setHint("请输入密码");

        dengPresenter = new DengPresenter(this);

    }


    @OnClick({R.id.tv_registe_login,R.id.tv_registe_refactor,R.id.bt_login})


    void onClick(View view) {


        switch (view.getId()) {

            //为跳转到第二个页面的TextView设置了点击事件
            case R.id.tv_registe_refactor:
                Toast.makeText(MainActivity.this, "再想想就记起密码了", Toast.LENGTH_SHORT).show();

                break;
            case R.id.tv_registe_login:
                startActivity(new Intent(MainActivity.this,Main2Activity.class));

                break;
            case R.id.bt_login:
                String n = tvUsername.getText().toString();
                String p = txPassworld.getText().toString();


                boolean judge = isMobile(n);
                if (judge == true) {
                    dengPresenter.getDataju("http://120.27.23.105/user/login?mobile="+n+"&password="+p+"");

                } else {
                    Toast.makeText(MainActivity.this,"请输入正确手机号",Toast.LENGTH_LONG).show();


                }



                break;
        }


    }


    @Override
    public void onSuccess(DengBean zhubean) {
        if ("0".equals(zhubean.getCode())){

            Toast.makeText(MainActivity.this,"成功",Toast.LENGTH_LONG).show();
            Intent intent=new Intent(MainActivity.this,Main3Activity.class);
            startActivity(intent);

        }else
        {
            Toast.makeText(MainActivity.this,"请输入正确得每一项",Toast.LENGTH_LONG).show();
        }


    }
    /**
     * 验证手机格式
     */
    public static boolean isMobile(String number) {
   /*
   移动:134135136137138139150151157(TD)158159187188
   联通:130131132152155156185186
   电信:133153180189、(1349卫通)
   总结起来就是第一位必定为1,第二位必定为358,其他位置的可以为0-9
   */
        String num = "[1][358]\\d{9}";//"[1]"代表第1位为数字1"[358]"代表第二位可以为358中的一个,"\\d{9}"代表后面是可以是09的数字,有9位。
        if (TextUtils.isEmpty(number)) {
            return false;
        } else {
            //matches():字符串是否在给定的正则表达式匹配
            return number.matches(num);
        }
    }

}


你可能感兴趣的:(京东登录)