20165205 2017-2018-2 《Java程序设计》实验四 Android程序设计
实验内容
实验四 Android程序设计-1
Android Stuidio的安装测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十四章:
- 安装 Android Stuidio
- 完成Hello World, 要求修改res目录中的内容,Hello World后要显示自己的学号,提交代码运行截图和码云Git链接,截图没有学号要扣分
- 学习Android Stuidio调试应用程序
- 操作过程:
修改res
目录下的layout
文件夹中的activity_main.xml
布局文件,将其中的android:text="Hello World!"
改为android:text="Hello World!20155314"
实验四 Android程序设计-2
Activity测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十五章:
- 构建项目,运行教材相关代码
- 创建 ThirdActivity, 在ThirdActivity中显示自己的学号,修改代码让MainActivity启动ThirdActivity
- 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分
实验四 Android程序设计-3
UI测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十六章:
- 构建项目,运行教材相关代码
- 修改代码让Toast消息中显示自己的学号信息
- 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分
1.构建项目,运行教材相关代码
2.修改代码让Toast消息中显示自己的学号信息
实验四 Android程序设计-4
布局测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十七章:
- 构建项目,运行教材相关代码
- 修改布局让P290页的界面与教材不同
- 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分
1.构建项目,运行教材相关代码
2.修改布局让P290页的界面与教材不同
- 操作过程:
修改activity_main.xml
中代码
实验截图:
实验四 Android程序设计-5
事件处理测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十八章:
- 构建项目,运行教材相关代码
- 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分
构建项目,运行教材相关代码
课本代码(P298):
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++]); }
运行结果截图:
(三)UI测试
- 构建项目,运行教材相关代码
- 修改代码让Toast消息中显示自己的学号信息
- 实验代码:
MainActivity.java:
package com.example.dell1.basiccomponents; import android.content.Context; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.app.Activity; import android.util.AttributeSet; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btnshow1=(Button) findViewById(R.id.btn1); btnshow1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v){ Toast toast = Toast.makeText(MainActivity.this,"20155314刘子健", Toast.LENGTH_LONG); toast.show(); } }); } @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; } /* @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id. id_action_add: //事件 break; case R.id. id_action_delete: //事件 break; } return true; }*/ }
activity_main:
<?xml version="1.0" encoding="utf-8"?> <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="@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.dragon.toast.Main"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="20165" android:id="@+id/btn1" android:layout_alignParentTop="true" android:layout_marginTop="31dp" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> </RelativeLayout>
- 运行结果截图:
- 实验代码:
“自己动手,丰衣足食。”
本次Java实验让我更切身感受到动手实践的重要性,避免眼高手低,勤于动手、热衷实践才是学好一切的王道。
6-2017-2 《Java程序设计》实验四 Android程序设计