20175201张驰 实验四 Android 开发

4-1:【Android Studio安装】安装过程中出现的错误:参考https://blog.csdn.net/weixin_38277423/article/details/80254483

1.The SDK location is in inside studio install location
错误描述:The SDK location is in inside studio install location
解决方法:这个是由于SDK的安装目录是在Android Studio(简称:AS)的安装目录下,所以只需要在AS的安装目录外新建一个文件夹,并把SDK指定到这个目录下即可。
示例:AS 安装目录为-- D:android-studio,只要SDK指定在这个目录外就可以了。

2.Android sdk location should not contain whitespace
解决方法:SDK的目录名称不能有空格。

3.20175201张驰 实验四 Android 开发

原因:
在第一次安装AS,启动后,检测到电脑没有SDK。

知道了原因,自然有解决方法,可以在以后安装sdk,或者设置初次打开AS,不下载sdk

解决方法:
第一种:
点击Cancel,在后续的界面再安装SDK。
20175201张驰 实验四 Android 开发
20175201张驰 实验四 Android 开发

第二种:设置初次打开AS,不下载sdk
1、在这个Android studio的安装目录下,找到下面这个文件: inidea.properties
2、设置初次打开AS,不检测SDK。使用记事本打开,文件末尾添加一行:
  disable.android.first.run=true
网上大部分介绍这种方法,但是治标不治本,SDK没有下载,就算进入界面了,也用不了。还是要去下载SDK。
安装完成Android Studio
20175201张驰 实验四 Android 开发

创建项目:
红色方框选中的Start a new Android Studio project选项通常是我们课程里最常使用的,用于创建一个新的Android项目。
在此介绍一下其他的选项:
Open an existing Android Studio Project:打开已有的Android Studio项目。在经历一段时间的学习后,如果你想继续编辑之前的项目,或者打开一个从网上下载的例子,你可以点击此选项。
Check out project from Version Control:从版本控制库中获取项目。对于团队开发来说,版本控制是必不可少的工具。此选项允许你从GitHub、Google Cloud以及TortoiseSVN等处同步项目。事实上,Android Studio对于这些版本控制工具的支持也是很好的,你可以在设置中进行设定。
Import project(Eclipse ADT, Gradle, etc.):导入其他开发环境中的项目。通过该选项你可以将在Eclipse等处生成的项目迁移到Android Studio的开发环境中。
Import an Android code sample:导入Android代码样例。该功能将从Google及其合作伙伴那里读取示例的列表,你可以下载并查看一些优秀的项目并继续编辑它们。

20175201张驰 实验四 Android 开发
20175201张驰 实验四 Android 开发

更改acitvity_main.xml 中的代码:

20175201张驰 实验四 Android 开发
20175201张驰 实验四 Android 开发

4-2:
实验要求:

参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十五章:
构建项目,运行教材相关代码
创建 ThirdActivity, 在ThirdActivity中显示自己的学号,修改代码让MainActivity启动ThirdActivity
提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分

步骤:
20175201张驰 实验四 Android 开发
20175201张驰 实验四 Android 开发
1.MainActivity:

package com.besti.is.zc.secondactivitydemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = new Intent(this,ThirdActivity.class);
    startActivity(intent);
}

}
2.左上角file->new->Activity->empty Activity创建ThirdActicity

20175201张驰 实验四 Android 开发
3.activity_main.xml

<android.support.constraint.ConstraintLayout xmlns:andro
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="wyhy.activity.MainActivity">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="20175201zc"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

4.activity_third.xml

<android.support.constraint.ConstraintLayout xmlns:andro
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:layout_width="144dp"
    android:layout_height="26dp"
    android:text="20175201zc"
    tools:ignore="MissingConstraints"
    tools:layout_editor_absoluteX="109dp"
    tools:layout_editor_absoluteY="242dp" />

</android.support.constraint.ConstraintLayout>

运行截图:
20175201张驰 实验四 Android 开发
4-3:UI测试

实验要求

参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十六章:
构建项目,运行教材相关代码
修改代码让Toast消息中显示自己的学号信息
提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分

步骤:

1.Main_Activity

package com.besti.is.zc.ui;

import android.content.Intent;
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);
    Toast.makeText(this,"20175201,Toast.LENGTH_LONG).show();
}

}

2.activity_main.xml

<android.support.constraint.ConstraintLayout xmlns:andro
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="wyhy.ui.MainActivity">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="20175201"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>
运行截图:
20175201张驰 实验四 Android 开发
布局测试

实验要求
-参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十七章:

构建项目,运行教材相关代码
修改布局让P290页的界面与教材不同
提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分

步骤:
1.activity_main.xml

<RelativeLayout
xmlns:andro

android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="2dp"
android:paddingRight="2dp">

<Button
    android:
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Home"
    android:layout_marginRight="80dp"
    android:layout_marginEnd="80dp"
    android:layout_alignBaseline="@+id/saveButton"
    android:layout_alignBottom="@+id/saveButton"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />
<Button
    android:
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Back"
    android:layout_marginBottom="100dp"
    android:layout_alignParentBottom="true"
    android:layout_toLeftOf="@+id/cancelButton"
    android:layout_toStartOf="@+id/cancelButton"
    android:layout_marginRight="50dp"
    android:layout_marginEnd="50dp" />
<ImageView
    android:layout_width="100dp"
    android:layout_height="150dp"
    android:padding="10dp"
    android:src="@android:drawable/ic_btn_speak_now"
    android:

    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />
<LinearLayout
    android:
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center|bottom"
    android:background="@android:color/white"
    android:orientation="horizontal"
    android:layout_marginBottom="50dp"
    android:layout_above="@+id/imageView2"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true">
    <Button
        android:
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Filter" />
    <Button
        android:
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Share" />
    <Button
        android:
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Delete" />
</LinearLayout>

运行截图:(这一项感觉直接改代码有些麻烦,直接图形操作界面)
20175201张驰 实验四 Android 开发

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

  • 构建项目,运行教材相关代码
  • 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分

步骤

1.MainActivity

package com.besti.is.zc.multicolorclock;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AnalogClock;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AnalogClock;
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++]);
}
}

2.activity_main


运行截图:
20175201张驰 实验四 Android 开发
点击换色:
20175201张驰 实验四 Android 开发

20175201张驰 实验四 Android 开发

20175201张驰 实验四 Android 开发

20175201张驰 实验四 Android 开发

我不会发动图,所以就发了几个颜色的图片