Train ---Build you First App

本文提供了一套App开发流程指南,详细介绍了ViewGroup对象的使用、事件处理函数的编写方法以及Intent的基本概念。通过实例解析了布局管理、事件响应和组件间通信的关键步骤,帮助开发者构建功能完善的移动应用。

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

这篇文档主要是指导新手写一个App,下面是我以前没注意,然后在这篇文档中学到的。
1、ViewGroup对象是不可见的View容器,它定义子View如何布局。
原文是:ViewGroup Objects are invisible View containers that define how the child Views laid out.
2、点击事件函数的另一种写法
在xml 文件中 android:onClick = “functionName”
在对应的activity中,写functionName的实现,这里要注意三点
(1)必须是pubic类型
(2)返回必须是void
(3)必须有一个View的参数

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="sendMessage"
        android:text="sendMES"/>

 public void sendMessage(View view){
        Intent intent = new Intent(this,DisplayMessage.class);
        String sendMessage_str = mSendMessage_et.getText().toString();
        intent.putExtra(MESSAGE,sendMessage_str);
        startActivity(intent);
    }

3、Intent是在运行期对分离组件(Android有四大组件)进行绑定的对象,Intent表达了app想要做什么。
原文:an Intent is an object that provides runtime binding between separate components. The Intent represents an app’s “intent to do something”.
4、onOptionsItemSelected()与Hierarchical Parent
Hierarchical Parent:在Android4.1(API16)以上可以在AndroidManifest.xml文件中用android:parentActivityName=”.MainActivity”属性指定它的父activity,在低版本的系统中可以用支持库利用下面的方式来实现,value值为父activity的名

<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.administrator.firstappdema.MainActivity" />

这个属性是定义一个activity的父层次的activity,系统利用这个属性实现默认的导航行为,比如说“UP”button,它的默认实现就是onOptionsItemSelected()。
举个例子说明一下,UP和BACK键
A——>B——>C(A启动B,B启动C)
假定,A是C的父activity,那么从C按UP键就会返回A,而摁下BACK键就会返回B
官方给出的UP和BACK的区别:
The Up button is used to navigate within an app based on the hierarchical relationships between screens.
The system Back button is used to navigate, in reverse chronological order, through the history of screens the user has recently worked with. It is generally based on the temporal relationships between screens, rather than the app’s hierarchy.
就是说Up是利用的系统层级关系,而Back利用的是时间关系。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值