这篇文档主要是指导新手写一个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利用的是时间关系。