DecorView, androiddecorview

Source: Internet
Author: User

DecorView, androiddecorview

1. DecorView is the top View of the entire Window interface.

2. DecorView has only one child element, LinearLayout. Indicates the entire Window interface, including the notification bar, title bar, and content display bar.

3. LinearLayout contains two FrameLayout sub-elements.

(20) The title bar display interface. Only one TextView displays the application name. You can also customize the title bar. The loaded custom title bar View will be added to FrameLayout.

(21) shows the content bar. Is the layout interface loaded by the setContentView () method.

Tool View:

1.

View the ViewTree result for hierarchyviewer bat in the tools folder of the SDK:

(The title bar is not replaced at this time)

 

2. Change of ViewTree after the title bar is replaced:

The green area changes to the layout of the title. xml file to be loaded.

The title. xml content is:

123456789101112131415161718 <?xml version="1.0"encoding="utf-8"?><LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="fill_parent"  android:layout_height="fill_parent">  <ImageView    android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:src="@drawable/icon2"/>  <TextView      android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:id="@+id/title_tv"  android:textColor="#FFFFFF"  android:textStyle="bold"  android:text="@string/app_name"  /></LinearLayout>


 

The notification bar is drawn in LinearLayout 1, or in DecorView.

-----------------

Custom TitleBar code segment in CustomTitle under app package in ApiDemo

123 requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);setContentView(R.layout.custom_title);getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1);


 

After loading the custom titleBar, how can we find the elements in it? In fact, we can use findViewById, because the loaded custom layout is already in the DecorView tree.

What is findViewById.

FindViewById source code in activity

123 public View findViewById(int id) {    returngetWindow().findViewById(id);}


GetWindow (). findViewById is called. getWindow returns the source code in the Window by clicking in the window.

123 public View findViewById(int id) {    returngetDecorView().findViewById(id);}


Therefore, the search starts from the top-level of DecorView.

The following article may help you better understand the situation:

Relationship http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2013/0322/1055.html between Activity, Window and View in Android

Related Keywords:
Related 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.