20155338 2016-2017-2《Java程序设计》实验四Android程序开发实验报告

本文介绍了通过修改Android项目的XML布局文件来显示学号信息的方法,并展示了如何使用Intent在不同Activity间传递数据,还涉及了Toast消息的使用及界面调整。

2016-2017-2 20155338 《Java程序设计》实验四Android程序开发实验报告

实验过程及成果展示

1、修改res目录下的layout文件夹中的activity_main.xml布局文件,使得在模拟机上显示出自己的学号信息。

码云链接

代码如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.dell1.helloworld.MainActivity">

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

</android.support.constraint.ConstraintLayout>

截图如下:
1071544-20170522214100742-998499931.jpg

2、在MainActivity.java中利用Intent类,调用 startActivity方法,使其启动ThirdActivity ,搞清楚ThirdAvtivity是如何利用其它文件设定的“message”显示自己学号的。

码云链接

MainActivity.java代码如下:

package com.example.dell1.activitydemo;

//import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.TextView;


public class MainActivity extends Activity implements
    OnTouchListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView tv = (TextView) findViewById(R.id.textView1);
        tv.setOnTouchListener(this);
    }
    @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 onTouch(View arg0, MotionEvent event) {
        Intent intent = new Intent(this, ThirdActivity.class);
        intent.putExtra("message", "20155312张竞予");
        startActivity(intent);
        return true;
    }
}

截图如下:
1071544-20170522214121273-1821846670.jpg

3、导入Toast包,让虚拟机显示默认位置的Toast消息。

码云链接

运行截图如下:
1071544-20170522214136773-1088471946.jpg

4、探索图形化界面,改变其界面方式。

码云链接

运行截图如下:
1071544-20170522214156007-785430519.jpg

5、AndroidManifest

码云链接

.xml文件代码如下:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.dell1.helloworld"
    android:versionCode="1"
    android:versionName="1.0">

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

        <activity
            android:name="com.example.dell1.helloworld.MainActivity"
            android:label="@string/app_name">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

运行截图如下:
1071544-20170522214216601-1130027140.jpg

转载于:https://www.cnblogs.com/Hdywan/p/6891585.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值