03

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.qq.MainActivity" >

    <TextView
        android:id="@+id/tv_account"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" 
        android:background="#FFFFFF"
        android:text="帐号:"
        android:textSize="30dp"
 
        />
     <TextView
         android:id="@+id/tv_account1"
         android:layout_width="fill_parent"
         android:layout_height="40dp"
         android:layout_below="@+id/tv_account"
         android:layout_centerVertical="true"
         android:background="#FFFFFF"
         android:text="密码:"
         android:textSize="30dp"
         
          />

     <Button
         android:id="@+id/button1"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:layout_alignLeft="@+id/tv_account1"
         android:layout_alignRight="@+id/tv_account1"
         android:layout_below="@+id/tv_account1"
         android:background="#545bcb"
         android:textColor="#ffffff"
         android:textSize="20dp"
         android:text="登录" 
         android:onClick="CCC"/>

     <ImageView
         android:id="@+id/imageView1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_centerHorizontal="true"
         android:layout_above="@+id/tv_account"
         android:src="@drawable/logo" />

     <EditText
         android:id="@+id/username"
         android:layout_width="400dp"
         android:layout_height="40dp"
         android:layout_below="@+id/tv_account"
         android:ems="10" 
         android:gravity="center"
         android:background="@null"
         />

     <EditText
         android:id="@+id/password"
         android:layout_width="match_parent"
         android:layout_height="40dp"
         android:layout_centerInParent="true"
         android:ems="10"
         android:gravity="center"
         android:background="@null"
          />

RelativeLayout>
package com.example.qq;

import android.support.v7.app.ActionBarActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity implements View.OnClickListener{

    EditText username;
    EditText password;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         username = (EditText)findViewById(R.id.username);
         password = (EditText)findViewById(R.id.password);
          
    }

    @SuppressLint("ShowToast")
    public void CCC(View view){

        String username1 = username.getText().toString();
        String password1 = password.getText().toString();
       if(username1.equals("123456") && password1.equals("123456")) {
            
            Toast.makeText(MainActivity.this, "登录成功", 0).show();
       }
       else {
           Toast.makeText(MainActivity.this, "登录失败", 0).show();
       }
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        
    }


}

03_第1张图片03_第2张图片

你可能感兴趣的:(03)