Android——Activity练习

本文详细介绍了Android应用程序中两个Activity的定义与启动过程,包括如何通过AndroidManifest.xml配置启动活动,以及如何在Java代码中设置Activity布局并初始化组件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

manifests里的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.chenshuai.test">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <!--谁在前启动谁-->
        <activity android:name=".Axtivity2">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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


        </activity>

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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


    </application>

</manifest>

 

layout里新建的layoutactivity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="1">

    <!--匹配父窗口  match_parent
        包裹内容    wrap_content-->
    <TextClock
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

       android:text="大家好"


      />

</LinearLayout>

layout里MainActivity

package com.hanqi.text3;

import android.app.Activity;
import android.os.Bundle;
//继承了Activity
public class MainActivity extends Activity {

    @Override //覆盖  重写了父类的onCreate()
    protected void onCreate(Bundle savedInstanceState) {
        //super  父类
        //调用了父类的方法
        super.onCreate(savedInstanceState);
        //设置Java代码和layout文件的关联
        //通过R文件的id值
        setContentView(R.layout.activity_main);
    }
}

 

java里新建的Activity2

package com.example.chenshuai.test;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

/**
 * Created by chenshuai on 2016/3/16.
 */
public class Axtivity2 extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.layoutactivity);

        System.out.println("这是我运行的第一个Activity");

        //输出日志
        Log.d("test","Log输出的信息");

        Log.w("test","Log输出的信息");//warning 蓝色

        Log.e("test","Log输出的信息");//eror 红色

        Log.i("test","Log输出的信息");

        Log.v("test","Log输出的信息");

    }
}

转载于:https://www.cnblogs.com/cuikang/p/5289106.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值