关闭

仿美团(二)之登录界面

436人阅读 评论(0) 收藏 举报
分类:

直接上图片,先看看了解了解:

                                       图片一

                                         图片二

   布局思路:最外层用LinearLayout线性布局,整个背景用#ededed灰色填充满,设置垂直布局orientation="vertical",把每个子布局模块放入其中,设置他们各自相应的属性;看代码就明白了:

   

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ededed"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:background="#05c0af"
        android:orientation="horizontal" >

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="#05c0af"
            android:src="@drawable/ic_action_back" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="3dp"
            android:background="#05c0af"
            android:src="@drawable/ic_action_home" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="3dp"
            android:text="登录"
            android:textColor="#ffffff"
            android:textSize="20sp" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="170dp"
            android:background="#05c0af"
            android:text="找回密码"
            android:textColor="#ffffff"
            android:textSize="18sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_margin="10dp"
        android:background="#ffffff"
        android:orientation="vertical"
        android:paddingLeft="10dp"
        android:paddingRight="10dp" >

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dp"
            android:orientation="horizontal" >

            <EditText
                android:id="@+id/register_user"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="手机|邮箱|用户名"
                android:maxLength="15"
                android:textSize="20sp" />

            <ImageButton
                android:id="@+id/register_user_clear"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_alignBottom="@id/register_user"
                android:background="@drawable/selector_drawable_select_clear" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dp"
            android:orientation="horizontal" >

            <EditText
                android:id="@+id/register_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="密码"
                android:password="true"
                android:maxLength="15"
                android:textSize="20sp" />

            <ImageButton
                android:id="@+id/register_password_clear"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@id/register_password"
                android:layout_alignParentRight="true"
                android:layout_marginRight="30dp"
                android:background="@drawable/selector_drawable_select_clear" />
        </RelativeLayout>
    </LinearLayout>

    <Button
        android:id="@+id/RegisterBut"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/selector_drawable_registerbut"
        android:text="登录"
        android:textColor="#ffffff" 
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"/>
       <LinearLayout android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:orientation="horizontal"
           android:layout_marginLeft="12dp"
           android:layout_marginTop="10dp">
           <Button 
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:text="免费注册"
               android:textSize="20sp"
               android:textColor="#05c0af"
               android:background="#ededed"/>
           <Button android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:text="无账号快速登录"
               android:textSize="25sp"
               android:textColor="#05c0af"
               android:layout_marginLeft="85dp"
               android:background="#ededed"/>
       </LinearLayout>
       <Button android:layout_width="match_parent"
               android:layout_height="50dp"
               android:text="使用合作网站账号进行登录"
               android:textSize="15sp"
               android:textColor="#05c0af"
               android:background="@drawable/login_sliding_drawer_header"
               android:layout_marginTop="140dp"/>
</LinearLayout>

      在java代码中就要对这些按钮键进行监听:
     

package com.myandroid.meituan;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

public class RegisterActivity extends Activity {
	private EditText mEditViewUser, mEditViewPassword;
    private ImageButton  mClearUserBut,mClearPasswordBut;
    private Button    mRegisterBut;
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_register);
         
		mRegisterBut = (Button) findViewById(R.id.RegisterBut);
		mEditViewUser = (EditText) findViewById(R.id.register_user);
		mEditViewPassword = (EditText) findViewById(R.id.register_password);
		mClearUserBut =  (ImageButton) findViewById(R.id.register_user_clear);
		mClearPasswordBut =  (ImageButton) findViewById(R.id.register_password_clear);
		//登录按钮监听
		mRegisterBut.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				if (mEditViewUser.getText().toString().equals("tiangmei")//判断用户名和密码文本输入框中的字符是否与设置匹配
						&& mEditViewPassword.getText().toString().equals("123456")) {
					startActivity(new Intent(RegisterActivity.this,LoadingActivity.class));//匹配成功跳转到指定的Activity
					
				} 
				 else if(mEditViewUser.getText().toString().equals("")
						|| mEditViewPassword.getText().toString().equals("")){//判断是否为空
					Toast.makeText(RegisterActivity.this, "账号密码不能为空\n请输入后再登录!",
							Toast.LENGTH_LONG).show();//吐丝对话框弹出提示信息
				}
				 else{
					 Toast.makeText(RegisterActivity.this, "账号密码不正确\n请检查后再输入!",
								Toast.LENGTH_LONG).show();
				 }
			}
		});
		//监听用户名清除按钮
		mClearUserBut.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				mEditViewUser.setText("");//当点击清除键时,文本框中的内容置为空
			}
		});
		//监听密码清除按钮
		mClearPasswordBut.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				mEditViewPassword.setText("");

			}
		});
		
		mClearUserBut.setVisibility(View.INVISIBLE);//设置用户名清除按钮在启动Activity时不可见
		//监听用户名编辑
		mEditViewUser.addTextChangedListener(new TextWatcher() {
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {

				if (s.length() > 0) {//判断当有输入字符时清除键可见,空字符时清除键隐藏
					mClearUserBut.setVisibility(View.VISIBLE);
				} else {
					mClearUserBut.setVisibility(View.INVISIBLE);
				}
			}
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
			}
			public void afterTextChanged(Editable s) {
			}
		});
		
		mClearPasswordBut.setVisibility(View.INVISIBLE);//设置密码清除按钮在启动Activity时不可见
		mEditViewPassword.addTextChangedListener(new TextWatcher() {//监听密码编辑
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
				if (s.length() > 0) {//判断当有输入字符时清除键可见,空字符时清除键隐藏
					mClearPasswordBut.setVisibility(View.VISIBLE);
				} else {
					mClearPasswordBut.setVisibility(View.INVISIBLE);
				}
			}
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
			}
			public void afterTextChanged(Editable s) {
			}
		});
	}
}


 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:48905次
    • 积分:1114
    • 等级:
    • 排名:千里之外
    • 原创:53篇
    • 转载:62篇
    • 译文:1篇
    • 评论:6条
    文章分类
    最新评论