接下来几天我们会用android来写一个简单的记事本例子。记事本的基本功能包括:登录注册,最新记事,所有记事,添加记事,管理记事等。
几天我们先来介绍记事本的第一个模块--登录注册界面。
第一,我们新建一个工程MyNotepad。
第二,添加布局文件,在/res/layout文件夹下添加一个文件activity_login.xml,文件内容如下(在文件中会使用到/res/values文件加下的strings.xml文件,请参考下面strings.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:gravity="center_vertical" >
<RelativeLayout
android:id="@+id/rlname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" >
<TextView
android:id="@+id/tvname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:text="@string/name"
android:textSize="20sp" />
<EditText
android:id="@+id/name"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:hint="@string/namehint"
android:layout_toRightOf="@id/tvname"
android:textSize="18sp"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/rlpwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/rlname"
android:layout_margin="5dp" >
<TextView
android:id="@+id/tvpwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pwd"
android:layout_marginLeft="60dp"
android:textSize="20sp" />
<EditText
android:id="@+id/pwd"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:hint="@string/pwdhint"
android:layout_toRightOf="@id/tvpwd"
android:textSize="18sp"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/rlbtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/rlpwd"
android:layout_margin="5dp" >
<Button
android:id="@+id/register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/register"
android:layout_marginLeft="60dp"
android:textSize="22sp" />
<Button
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/login"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@id/register"
android:textSize="22sp"/>
</RelativeLayout>
</RelativeLayout>
里面控件的文字说明在/res/values/strings.xml中,其内容如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">我的记事本</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="name">用户名:</string>
<string name="namehint">请输入用户名</string>
<string name="pwd">密    码:</string>
<string name="pwdhint">请输入密码</string>
<string name="register">注册</string>
<string name="login">登录</string>
<string name="repwd">确认密码:</string>
<string name="repwdhint">请再次输入密码</string>
</resources>
接下来是注册界面,其实注册界面和登录界面很像。具体做法如下:在/res/layout文件夹下添加文件activity_register.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:gravity="center_vertical" >
<RelativeLayout
android:id="@+id/rlname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" >
<TextView
android:id="@+id/tvname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:text="@string/name"
android:textSize="20sp" />
<EditText
android:id="@+id/name"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:hint="@string/namehint"
android:layout_toRightOf="@id/tvname"
android:textSize="18sp"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/rlpwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/rlname"
android:layout_margin="5dp" >
<TextView
android:id="@+id/tvpwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pwd"
android:layout_marginLeft="60dp"
android:textSize="20sp" />
<EditText
android:id="@+id/pwd"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:hint="@string/pwdhint"
android:layout_toRightOf="@id/tvpwd"
android:textSize="18sp"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/rlrepwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/rlpwd"
android:layout_margin="5dp" >
<TextView
android:id="@+id/tvrepwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/repwd"
android:layout_marginLeft="60dp"
android:textSize="20sp" />
<EditText
android:id="@+id/repwd"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:hint="@string/repwdhint"
android:layout_toRightOf="@id/tvrepwd"
android:textSize="18sp"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/rlbtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/rlrepwd"
android:layout_margin="5dp" >
<Button
android:id="@+id/register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/register"
android:layout_marginLeft="100dp"
android:textSize="22sp" />
</RelativeLayout>
</RelativeLayout>
布局文件已经完成,接下来是activity。
第三,添加acticity,我们在src下新建一个包com.exceptionhelp.activity,同时新建两个java文件,LoginActivity.java和RegisterActivity.java。
LoginActivity.java文件内容如下:
package com.exceptionhelp.activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class LoginActivity extends Activity {
private Button register = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
register = (Button) findViewById(R.id.register);
register.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
LoginActivity.this.startActivity(intent);
}
});
}
@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;
}
}
RegisterActivity.java文件内容如下:
package com.exceptionhelp.activity;
import android.app.Activity;
import android.os.Bundle;
public class RegisterActivity extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
}
}
现在如果运行程序,是不行的,因为我们新添加了acticity,而且我们工程的入口应该是LoginActivity而不是MainActivity,所以我们需要改一下AndroidManifest.xml。其内容如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exceptionhelp.activity"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.exceptionhelp.activity.LoginActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.exceptionhelp.activity.RegisterActivity"></activity>
</application>
</manifest>
源码下载地址
http://www.exceptionhelp.com/posts/542
分享到:
相关推荐
刚接触Kotlin的第一天,仿照QQ的登录界面,先写一个简单的登录界面,虽然笔者用的不是很熟,还在慢慢摸索,但是Kotlin是真的很简洁,笔者的实现效果如下: 登录界面代码如下: class LoginActivity
1、用户管理部分,原程序虽然可以注册多个用户,但是每个用户登录进系统后都是一样内容。本次考试要求支持不同用户登录,且每个用户有自己独立的内容,各个用户之间数据独立。 2、日记搜索部分,原程序只支持时间段...
基于Android的记事本,论文主要是对基于...通过这些功能模块的设、系统设计上,采用了B/S的结构,同时,也使用Android技术在动态页面上进行了设计,后台上采用Mysql数据库,是一个非常优秀的基于Android的记事本软件 。
1.点击该日志app后,进入欢迎activity中,然后欢迎activity调用欢迎页面并显示该页面,欢迎页面设计为2000ms自动消失,跳转到登录功能中。 2.由欢迎页面自动跳转到登录activity中,登录activity调动login页面,并...
主要设计功能:写日记、查日记、日记...2.Android UI布局技术;3利用Application帮助实现完全退出;4 Intent页面跳转技术;5.项目闪屏效果;6.利用AlertDialog、gallery和ImageButton以画廊的形式进行心情图片选择。
2.包含用户登录、注册,记事本新增、查看以及删除功能。 3.uniappWorkspace里面放的是代码,cashbook是前端页面代码,caskbookServer是后端代码,记事本.apk可以直接安装(推荐发送到微信里面下载)。 4.在本地运行...
自己写的一个简单的记事本app,效果如下: 一、首先是第一个界面的编写,最上面是一个TextView,中间是一个Linearlayout中嵌套一个listview布局,最下面是一个button。下面附上第一个页面的简单布局xml文件。 <...
100多个Android的实用开源小应用,包含Android -- 引导页面的实现 Android APP引导页大全 Android Push it单机版事件管理APP Android RecycleView+任意头尾布局+拖拽换位+拖拽删除demo Android sql练习合集 Android ...
综合运用Android的所有基础知识,包含ListView、Sqlite数据库、Adapter等,包含注册登录页面,非常适合Android初学者学习。 项目的设计过程、开发环境和具体运行演示可以参考我对应的博客:...
android上简单开发记事本,并实现记事本的增删改查功能,使用数据库完成记事本存储信息的功能,个个页面间跳转,页面的背景可以更换,简单的页面布局,适用于学生小白项目使用。
拥有下拉菜单,聊天界面拥有一个聊天机器人,使用图灵官网提供的api,每次进入都会以不同的话欢迎使用者 此部分还完成了课本第七章基于HTTP的网络访问。 音乐播放器使用的是本地的mp3文件,未联网。计算器可以实现...
该资源对应博客《安卓的记事本应用开发日志(二)》的简单页面和ListView的加载。仅仅是作为开发日志的历史版本,非正式版本。谨慎下载!
伴随着Android智能手机与平板电脑已经在我们生活大量的使用,越来越多的基于Android开发平台的应用也随之出现。现代化水平的不断提高。人们每天接触的信息量已经变得异常庞大,这就造成传统的纸质记录方式,已经不能...
具有四个Activity,对应注册页面,登陆页面,例表项页面与记事本编辑页面;本系统还包含ListView或RecycleView;使用了SharedPreferences对登陆密码进行存储与SQList对记事本记事内容进行存储。
Tcp服务端与客户端的JAVA实例源代码 2个目标文件 摘要:Java源码,文件操作,TCP,服务器 Tcp服务端与客户端的JAVA实例源代码,一个简单的Java TCP服务器端程序,别外还有一个客户端的程序,两者互相配合可以开发出超多...
Tcp服务端与客户端的JAVA实例源代码,一个简单的Java TCP服务器端程序,别外还有一个客户端的程序,两者互相配合可以开发出超多的网络程序,这是最基础的部分。 递归遍历矩阵 1个目标文件,简单! 多人聊天室 3...