DecorView creation and DecorView Creation

Source: Internet
Author: User

DecorView creation and DecorView Creation

When the handleResumeActivity method of ActivityThread is called during Activity startup, A PhoneWindow object associated with Activity is obtained first, and DecorView is obtained through PhoneWindow.

PhoneWindow. java

Public final View getDecorView () {if (mDecor = null) {installDecor ();} return mDecor;} private void installDecor () {if (mDecor = null) {// generate DecorView mDecor = generateDecor (); mDecor. setDescendantFocusability (ViewGroup. FOCUS_AFTER_DESCENDANTS); mDecor. setIsRootNamespace (true);} if (mContentParent = null) {// determine the layout content in DecorView Based on the Window style. mContentParent is the first sub-View of DecorView, it is also the parent View mContentParent = generateLayout (mDecor); final DecorContentParent decorContentParent = (DecorContentParent) mDecor of setContentView () in Activity onCreate. findViewById (R. id. decor_content_parent );}...}

 

DecorView is an internal class of PhoneWindow, inheriting FrameLayout, and generateDecor () is also like our custom View is a new DecorView, but there is only one featureId parameter, if it is-1, indicates that this View is a DecorView.

protected DecorView generateDecor() {  return new DecorView(getContext(), -1);}private final class DecorView extends FrameLayout {  public DecorView(Context context, int featureId) {    super(context);    mFeatureId = featureId;  }}

 

Therefore, the layout in DecorView is mainly determined by generateLayout (mDecor ).

Protected ViewGroup generateLayout (DecorView decor) {// obtain the Window style TypedArray a = getWindowStyle ();... final WindowManager windowService = (WindowManager) getContext (). getSysteService (Context. WINDOW_SERVICE); if (windowService! = Null) {final Display display = windowService. getdefadisplay display ();...} final Context context = getContext (); final int targetSdk = context.getApplicationInfo().tar getSdkVersion ();... windowManager. layoutParams params = getAttributes (); // Inflate the window decor int layoutResource; int features = getLocalFeatures (); if () {// determines whether features contain tags} else if () {// If features contains custom Title layoutResource = R. layout. screen_custom_title;} else {// if the window property does not have any decoration (no TitleBar, no ActionBar, etc.) layoutResource = R. layout. screen_simple;} mDecor. startChanging (); // You Can See That DecorView also loads the layout through inflate, the default layout resource of the system framework is in View in = mLayoutInflater under the frameworks \ base \ core \ res \ layout directory. inflate (layoutResource, null); decor. addView (in, new ViewGroup. layoutParams (MATCH_PARENT, MATCH_PARENT); mContentRoot = (ViewGroup) in; ViewGroup contentParent = (ViewGroup) findViewById (ID_ANDROID_CONTENT); if (contentParent = null) {// throw an exception }... mDecor. finishChanging (); return contentParent ;}

 

Therefore, DecorView is generated by loading the corresponding layout Resources in the frameworks \ base \ core \ res \ layout directory through the inflate () method based on different window attributes. As for how the LayoutInflate. inflate () method loads the layout file and parses and generates the View, it will be analyzed in the next article.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.