我的记事本项目之路(一)

        首先你得先想好你要做个什么样的记事本,它有什么样的功能呢?

        第一步先给它做一个登录界面,登录界面这里我采用的是关系布局也就是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);
        }

    }
}
要看精彩内容,请看下回分解.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值