Android 开发进阶 从小工到专家(一)Activity构成
Activity的构成并不是一个Activity对象再加上一个布局那么简单 再Activity和开发人员设置的视图之间还隔着两层。实际上视图会被设置给一个Window 类,这个Window中含有一个DecorView,这个DecorView才是窗口的顶级视图。
开发人员设置的布局会被设置到这个DecorView 的mContentParent布局中,也就是说Android中实际上内置了一些布局系统文件xml,
我们在xml中定义的视图最终会被设置到这些系统布局的特定节点下,这样就形成了整个decorview
从图中可以看到我们的Activity之下有一个PhoneWindow,这个PhoneWindow 是Window的实现类,然后Window之下包括一个
DecorView,DecorView实际上是页面的顶级视图,他从一些系统布局中加载,并且再运行时将开发人员设置给Activity的布局资源添加到系统布局mContentParent中 这样一来用户界面就被添加到系统布局中了。而系统布局会为我们设置好标题区域等,
下面是一个名为screen_title.xml 的系统布局文件
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2006 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!--
This is an optimized layout for a screen, with the minimum set of features
enabled.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:fitsSystemWindows="true">
<!-- Popout bar for action modes -->
<ViewStub android:id="@+id/action_mode_bar_stub"
android:inflatedId="@+id/action_mode_bar"
android:layout="@layout/action_mode_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="?attr/actionBarTheme" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="?android:attr/windowTitleSize"
style="?android:attr/windowTitleBackgroundStyle">
<TextView android:id="@android:id/title"
style="?android:attr/windowTitleStyle"
android:background="@null"
android:fadingEdge="horizontal"
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<!--这里就是开发人员设置的布局 所填充的位置-->
<FrameLayout android:id="@android:id/content"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:foregroundGravity="fill_horizontal|top"
android:foreground="?android:attr/windowContentOverlay" />
</LinearLayout>
所以这就解释了 为什么我们写一个空布局 就产生了自带的标题 我们还需要使用theme去改变他