Android登录界面的实现
本篇博客主要给大家演示如何创建一个类似于下图展示的这么一个UI界面:
布局当中将会包括以下几个UI控件:
- TextView(To use highlight...)
- ImageButton(Facebook)
- ImageButton(LinkedIn)
- TextView(Why not email?)
- TextView(Highlight is based...)
- TextView(Please let us know...)
- TextView(We will not post things without...)
第一步布局背景设置
要将布局背景设置为白色,源码如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
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=".MainActivity" >
第二步TextView设置
拖动TextView控件到布局当中去,对登录界面和注册界面进行设计
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/etName"
android:layout_below="@+id/etName"
android:ems="10"
android:hint="请输入密码"
android:inputType="textPassword" >
</EditText>
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:ems="10"
android:hint="请输入用户名"
android:inputType="textPersonName" />
android:id="@+id/btButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/etPassword"
android:layout_below="@+id/etPassword"
android:layout_marginRight="66dp"
android:text="登录" />
android:id="@+id/btButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btButton"
android:layout_alignBottom="@+id/btButton"
android:layout_alignParentRight="true"
android:text="注册" />
<EditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入用户名"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/etName"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:hint="请输入密码"
android:ems="10"
android:inputType="textPassword" />
<EditText
android:id="@+id/etPassword2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/etPassword"
android:layout_centerHorizontal="true"
android:hint="请再次输入密码"
android:ems="10"
android:inputType="textPassword" />
<EditText
android:id="@+id/etAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/etPassword2"
android:layout_below="@+id/etPassword2"
android:hint="请输入邮箱"
android:ems="10"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/etPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_below="@+id/etAddress"
android:hint="请输入电话号码"
android:ems="10"
android:inputType="phone" />
<Button
android:id="@+id/btButton1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/etPhone"
android:layout_marginTop="30dp"
android:text="注册" />
第三步超链接设置
对布局中的登录界面和注册界面进行连接
import android.app.Activity;
import android.app.IntentService;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void toSecond(View view){
Intent intent=new Intent(this, ShowActivity.class);
startActivityForResult(intent, 1);
}
}
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show);
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.show, menu);
return true;
}
public void toFirstWithResult(View view){
Intent intent=new Intent();
setResult(RESULT_OK, intent);
finish();
}
}