What is the ViewStub inside DecorView?

1k Views Asked by At

I found that under decorView, with or without title or ActionBar, ViewStub would exist.

What's the use of it?

enter image description here

3

There are 3 best solutions below

2
On BEST ANSWER

basing on id of this view its is probably place/space/container for ActionMode layout. On some devices it may look like below (top bar above content, when ActionBar/Toolbar present then is replaced)

action mode example

3
On

ViewStub is kind of a View, that would be lazily inflated at a later time when needed.

In the graph you have you posted you can see action_mode_bar_stub id.

Clearly, it's not always that you would actually need that view to be inflated. You would only need that once user enters Contextual Action Mode. Thus, in order not to convolute the view hierarchy, that view would not be inflated until user would actually need that view to be displayed. Once inflated, view hierarchy would change and you no longer will see that ViewStub there.

0
On

Look at this file: https://github.com/aosp-mirror/platform_frameworks_base/blob/6bebb8418ceecf44d2af40033870f3aabacfe36e/core/res/res/layout/screen.xml

In this file, the actual code for action_mode_bar_stub:

<!-- 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"/>

There is says that it is the popout bar for action modes.