下载与安装Android Studio

  1. 下载地址:Download Android Studio
  2. 安装教程参考Android开发简易教程

实验内容

码云链接

任务一

  • 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十四章,完成Hello World, 要求修改res目录中的内容,Hello World后要显示自己的学号,自己学号前后一名同学的学号
  • 实验过程
    • 找到app下的res目录,点击layout中的activity_main.xml,修改其中的android:text="Hello World!"
  • 源代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!20165329 20165330 20165331"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout>
  • 运行结果截图

任务二

  • 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十五章:

    • 构建项目,运行教材相关代码
    • 创建ThirdActivity,在ThirdActivity中显示自己的学号,修改代码让MainActivity启动ThirdActivity
  • 实验过程
    • 创建ThirdActivity
    • 修改MainActivity中的代码
    • main中新建thirdactivity_main.xml并修改android:text="Hello World!"内容
  • MainActivity.java
package zyx.is.besti.edu.cn.helloworld;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(this,ThirdActivity.class);
startActivity(intent);
} }
  • thirdactivity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ThirdActivity"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="20165330张羽昕" />
</android.support.constraint.ConstraintLayout>
  • 运行结果截图

任务三

  • UI测试:参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十六章:

    • 构建项目,运行教材相关代码
    • 修改代码让Toast消息中显示自己的学号信息
  • MainActivity.java
package zyx.is.besti.edu.cn.helloworld;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.widget.Toast; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast toast=Toast.makeText(MainActivity.this, "20165330张羽昕",Toast.LENGTH_LONG);
toast.show(); } }
  • 运行结果截图

任务四

  • 布局测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十七章:

    • 构建项目,运行教材相关代码
    • 修改布局让P290页的界面与教材不同
  • activity_main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="2dp"
android:paddingRight="2dp">
<Button
android:id="@+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="20165330"
android:layout_marginTop="70dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<Button
android:id="@+id/saveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="张羽昕"
android:layout_below="@+id/cancelButton"
android:layout_alignLeft="@+id/cancelButton"
android:layout_alignStart="@+id/cancelButton"
android:layout_marginTop="23dp" />
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginTop="45dp"
android:padding="4dp"
android:src="@android:drawable/ic_dialog_email"
android:id="@+id/imageView"
android:layout_below="@+id/saveButton"
android:layout_centerHorizontal="true" />
<LinearLayout
android:id="@+id/filter_button_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center|bottom"
android:background="@android:color/white"
android:orientation="horizontal" >
<Button
android:id="@+id/filterButton"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Filter" />
<Button
android:id="@+id/shareButton"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Share" />
<Button
android:id="@+id/deleteButton"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Delete" />
</LinearLayout> <ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="160dp"
app:srcCompat="@mipmap/ic_launcher" />
</RelativeLayout>
  • 运行结果截图

任务五

  • 事件处理测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十八章:

    • 构建项目,运行教材相关代码
  • MainActivity.java
package zyx.is.besti.edu.cn.helloworld;

import android.app.Activity;

import android.graphics.Color;

import android.os.Bundle;

import android.view.Menu;

import android.view.View;

public class MainActivity extends Activity {

    int counter = 0;

    int[] colors = { Color.BLACK, Color.BLUE, Color.CYAN,

            Color.DKGRAY, Color.GRAY, Color.GREEN, Color.LTGRAY,

            Color.MAGENTA, Color.RED, Color.WHITE, Color.YELLOW };

    @Override

    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.menu_main, menu);

        return true;

    }

    public void changeColor(View view) {

        if (counter == colors.length) {

            counter = 0;

        }

        view.setBackgroundColor(colors[counter++]);

    }

}
  • activity_main.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:paddingBottom="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
tools:context=".MainActivity"> <AnalogClock
android:id="@+id/analogClock1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="90dp"
android:onClick="changeColor" />
</RelativeLayout>
  • 运行结果截图

遇到的问题及解决方法

  • 在运行Android Studio时,发现创建的java程序有红J标识,非C标识

解决办法:在网上找了很多办法,参考Android Studio解决未识别Java文件(出现红J)问题,在修改后并重启电脑再打开,发现成功解决

  • Toast的makeText()方法报错

解决办法:参考android Toast大全(五种情形)建立属于你自己的Toast,最终解决方法是在主函数里利用事件处理器,设置了一个按钮来调用这个提示。

2017-2018-2 20165330 实验四《Android程序设计》实验报告的更多相关文章

  1. 20165230 《Java程序设计》实验四 Android程序设计实验报告

    20165230 <Java程序设计>实验四 Android程序设计实验报告 一.实验报告封面 课程:Java程序设计 班级:1652班 姓名:田坤烨 学号:20165230 成绩: 指导 ...

  2. 实验四 Android程序设计 实验报告

    实验四 Android程序设计 实验报告 目录 代码托管地址 Android程序设计-1 Android程序设计-2 Android程序设计-3 Android程序设计-4 Android程序设计-5 ...

  3. 20155326 实验四 Android程序设计实验报告

    20155326 实验四 Android程序设计实验报告 实验内容 1.基于Android Studio开发简单的Android应用并部署测试; 2.了解Android.组件.布局管理器的使用: 3. ...

  4. 20162325金立清 实验四 Android程序设计 实验报告

    实验四 Android程序设计 实验报告 代码托管地址 码云链接 实验内容 安装使用Android Stuidio Activity测试 UI测试 布局测试 事件处理测试 Android程序设计-1 ...

  5. 实验四 Android程序设计 实验报告 20162305李昱兴

    实验四 Android程序设计 实验报告 20162305李昱兴 一.Android Studio的安装测试 1.有关该软件 Android Studio,是基于Itellij IDEA的一款流行的I ...

  6. 20172302《程序设计与数据结构》实验四Android程序设计实验报告

    课程:<程序设计与数据结构> 班级: 1723 姓名: 侯泽洋 学号:20172302 实验教师:王志强老师 实验日期:2018年5月30日 必修/选修: 必修 1.实验内容 (1)And ...

  7. 20155328 实验四 Android程序设计 实验报告

    20155328 实验四 Android程序设计 第24章 初识Android 提交点1:完成HelloWorld并显示自己的学号 安装Android Studio后,创建了属于自己的Project( ...

  8. 2016-2017-2 20155312 实验四Android程序设计实验报告

    遇到的问题及解决过程 「问题1」Android Studio-R文件出错 解决:参考Android Studio-R文件错误的解决办法步骤如下: 第一步:检查xml文件,R文件错误通常是由于我们的xm ...

  9. 20165235实验四 Android程序设计

    20165235实验四 Android程序设计 实验课程:JAVA编程设计 实验名称:Android开发 姓名:祁瑛 学号:20165235 实验时间:2018.05.16 指导老师:娄家鹏 Andr ...

  10. 实验四 Android程序设计

    20155224 实验四 Android程序设计 实验报告 实验报告封面: 课程:Java程序设计 班级:1652班 姓名:王高源 学号:20165225 指导教师:娄嘉鹏 实验日期:2018年5月1 ...

随机推荐

  1. Atitit. 状态模式(State)attilax 总结 跟个策 略模式的区别

    Atitit. 状态模式(State)attilax 总结 跟个策 略模式的区别 1. 状态模式(State)概览 1 2. 状态的维护和转换:① 在Context 中.② 在状态的处理类中.2 3. ...

  2. atitit.软件开发概念--过滤和投影 数据操作

    atitit.软件开发概念--过滤和投影 数据操作 投影的本质及扩展 物体在太阳光的照射下形成的影子(简称日影)就是平行投影.日影的方向可以反映时间 投影还比喻此物通过彼物表现出来的迹象. 作者::老 ...

  3. Objective-C的内存管理(一)黄金法则的理解

    转自:http://blog.csdn.net/lonelyroamer/article/details/7666851 一.内存管理黄金法则: The basic rule to apple is ...

  4. PaaS 平台的网络需求

    在使用 Docker 构建 PaaS 平台的过程中,我们首先遇到的问题是需要选择一个满足需求的网络模型: 让每个容器拥有自己的网络栈,特别是独立的 IP 地址 能够进行跨服务器的容器间通讯,同时不依赖 ...

  5. linux 编译kernel与svn版本冲突解决方法 [drivers/gpu/mali/mali/common/mali_kernel_core.o] 错误 1

    问题: 系统正常编译linux系统kernel,安装svn后,kernel编译出错. 错误: CHK     include/linux/version.h  CHK     include/gene ...

  6. QQ连连看-外挂

    QQ连连看-外挂 2014-11-06 参考 [1] [视频教程] c语言实践课程之qq连连看辅助开发 [2] CE工具下载 [3] [原创]qq连连看外挂制作详解

  7. ipipe-3.10

    git://git.xenomai.org/ipipe-gch.git for-ipipe-3.10

  8. Android——Activity恢复用户用EditText输入的数据

    说明: 在横屏输入的内容,在Activity销毁后,即横屏后,获取用户输入的内容 步骤: 1.在xml页面定义EditText的id 2.用onSaveInstanceState保存用户输入的数据 ( ...

  9. 原生Orcale数据库连接

    package tj.test.demo; import java.sql.Connection;import java.sql.DriverManager;import java.sql.Prepa ...

  10. phpstorm 中文版 支持BUG调试 IDE

    下载地址:http://dx2.7down.net/soft/P/phpstorm8_cn.zip