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) { return getWindow().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) { return getDecorView().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