首先你得先想好你要做个什么样的记事本,它有什么样的功能呢?
第一步先给它做一个登录界面,登录界面这里我采用的是关系布局也就是RelativeLayout,
第二步采用表格布局TableLayout用来布局用户名和密码框,这里采用两组TextView与EditText,
第三步在设置两个Button按钮分别为登录和注册.
login.xml的具体代码如下:
<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:background="#ADFF2F"
android:layout_marginTop="8dip"
android:layout_marginBottom="8dip"
android:layout_marginLeft="8dip"
android:layout_marginRight="8dip"
>
<TableLayout
android:id="@+id/loginForm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
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.JiShiBen.LoginDialog"
android:background="#ADFF2F"
>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="用户名"
android:textSize="15pt" />
<!-- 输入用户名的文本框 -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请填写登录账号"
android:selectAllOnFocus="true" />
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="密码:"
android:textSize="15pt" />
<!-- 输入密码的文本框 -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:password="true" />
</TableRow>
</TableLayout>
<Button
android:id="@+id/btn_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/loginForm"
android:text="登录"
/>
<Button
android:id="@+id/btnLoginS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/btn_login"
android:layout_alignParentRight="true"
android:text="注册" />
</RelativeLayout>
然后就是登录功能的Activity的实现,这里由于是新手项目,所以没有复杂的验证功能,就实现一个简单的功能,点击登录后跳转LoginActivity.java的代码如下:
package com.example.jishiben;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class LoginActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
Button bn = (Button) findViewById(R.id.btn_login);
BtnOnClickListener listener = new BtnOnClickListener();
bn.setOnClickListener(listener);
}
class BtnOnClickListener implements OnClickListener {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(LoginActivity.this, MainActivity.class);
startActivity(intent);
}
}
}
要看精彩内容,请看下回分解.