第一部分:简答题(15分)
写出5个常见的组件以及常用的页面布局(5分)
两个Activity之间怎么传递数据?(5分)
简述List、Set、Map集合的区别?(5分)
第二部分:仿QQ登录功能(85分
1.开启显示开机页面,3秒后跳转到登录页面:
2. 点击登录按钮,当帐号和密码有一个未填写时,则友情提示帐号密码不能为
3.当帐号密码都填写了,但帐号密码填错给予错误提
4.当帐号密码填写正确,跳转到登录成功页面,并有欢迎语
5. 当点击退出,则弹出对话框提示是否退出
具体要求及推荐实现步骤:
1.设计登录窗口UI 界面和登录成功后UI 主界面窗口,摆放正确的控件
2.编写activity 底层处理代码,获取界面控件对象
3.在activity 注册登录按钮点击事件,判断账号密码,并作出相应提示
4.Intent 把账号名称传递数据到跳转的主界面的activity 显示欢迎语
5.正确账号密码:1、zhangsan,123;2、lisi,456;3、wangwu,147。
6.颜色对应:#1EB9F2
评分标准:
序号 | 功能列表 | 功能描述 | 分数 |
1 | 应用程序 | 能正确并完整创建应用程序 | 10分 |
2 | 界面 | 按要求设计界面并正确摆放控件 | 20分 |
3 | 登录功能 | 点击登录并对输入的账号密码进行判断,并做出相应提示 | 35分 |
4 | 欢迎页 | 完成页面跳转并实现数据传递,显示欢迎语,退出提示框 | 20分 |
写出5个常见的组件以及常用的页面布局(5分)
Button | 按钮 |
TextView | 文本 |
EditText | 输入框 |
Spinner | 下拉列表 |
RadioButton | 单选按钮 |
LinearLayout | 线性布局 |
TableLayout | 表格布局 |
RelativeLayout | 相对布局 |
两个Activity之间怎么传递数据?(5分)
两个Activity之间通过Intent对象进行值的传递
简述List、Set、Map集合的区别?(5分)
List | 有序允许有重复值 |
Set | 无序不予许有重复值 |
Map | 以键值对的形式存值,值可以重复,键不可以重复 |
使用了三个Activity,项目结构:
# 使用的图片资源
MainActivity.java
package vip.wfb.bigwork3;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//去除activity上边的框框
requestWindowFeature(Window.FEATURE_NO_TITLE);
//设置全屏显示
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//第一个参数,当前上下文。第二个参数,计时结束之后开启的页面
Intent intent = new Intent(getApplicationContext(), DengluActivity.class);
startActivity(intent);
finish();
}
}, 3000);
}
}
ZhuyeActivity.java
package vip.wfb.bigwork3;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import java.util.HashMap;
import java.util.Map;
public class ZhuyeActivity extends Activity {
//声明组件
private TextView text;
private Button but_tuichu;
private Map map = new HashMap();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//去掉顶部的小框框
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_zhuye);
//获取组件
but_tuichu = findViewById(R.id.but_tuichu);
text = findViewById(R.id.text_we);
//账号与人名对应
map.put("zhangsan", "张三");
map.put("lisi", "李四");
map.put("wangwu", "王五");
//获取用户登录的账号
final Intent intent = getIntent();
String name = intent.getStringExtra("name");
text.setText("欢迎您:" + map.get(name));
//创建单击监听
but_tuichu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialog.Builder(ZhuyeActivity.this)
.setTitle("确认退出")
.setIcon(R.drawable.ic_launcher_foreground)
.setMessage("是否确认退出!")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent1 = new Intent(getApplicationContext(), DengluActivity.class);
startActivity(intent1);
finish();
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "取消退出!", Toast.LENGTH_LONG).show();
}
})
.create()
.show();
}
});
}
}
DengluActivity
package vip.wfb.bigwork3;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class DengluActivity extends Activity {
//声明组件
private Button but_denglu;
private EditText edit_name;
private EditText edit_pwd;
//定义业务逻辑所需要的变量
private Map<String, String> map = new HashMap<String, String>();
private String name;
private String pwd;
boolean isName = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//去掉顶部的框框
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_denglu);
//获取组件
but_denglu = findViewById(R.id.but_denglu);
edit_name = findViewById(R.id.edit_name);
edit_pwd = findViewById(R.id.edit_pwd);
//储存账号密码
map.put("zhangsan", "123");
map.put("lisi", "456");
map.put("wangwu", "147");
//创建单击监听
but_denglu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//获取用户输入的值
name = edit_name.getText().toString();
pwd = edit_pwd.getText().toString();
//判断是否有忘记输入的内容
if (name.equals("") || name == null) {
Toast.makeText(getApplicationContext(), "请输入账号!", Toast.LENGTH_LONG).show();
} else if (pwd.equals("") || pwd == null) {
Toast.makeText(getApplicationContext(), "请输入密码!", Toast.LENGTH_LONG).show();
} else {
//判断输入的账号是否存在
Set<String> set = map.keySet();
for (String st : set) {
if (st.equals(name)) {
isName = true;
}
}
if (isName) {
//判断密码输入是否正确
if (map.get(name).equals(pwd)) {
//账号密码都正确跳转界面
Intent intent = new Intent(getApplicationContext(), ZhuyeActivity.class);
intent.putExtra("name", name);
startActivity(intent);
finish();
} else {
Toast.makeText(getApplicationContext(), "密码错误!", Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(getApplicationContext(), "没有此账号!", Toast.LENGTH_LONG).show();
}
}
}
});
}
}
# layout代码
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/welcom"
android:orientation="vertical">
LinearLayout>
activity_zhuye.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/text_we"
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center_vertical"
android:background="#1EB9F2"
android:textColor="#ffffff"
android:textSize="30sp" >
<Button
android:id="@+id/but_tuichu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="90dp"
android:layout_marginRight="30dp"
android:background="#1EB9F2"
android:text="退出"
android:textColor="#ffffff"
android:textSize="30sp" >
LinearLayout>
activity_denglu.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="90dp"
android:layout_gravity="center"
android:layout_marginTop="60dp"
android:src="@drawable/qq" >
<EditText
android:id="@+id/edit_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:hint="QQ账号/手机号/邮箱"
android:singleLine="true" >
<EditText
android:id="@+id/edit_pwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:hint="密码"
android:inputType="textPassword"
android:singleLine="true" />
<Button
android:id="@+id/but_denglu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#1EB9F2"
android:text="登录"
android:textColor="#ffffff"
android:textSize="20sp" />
LinearLayout>
#效果图#