Capturing a pointer to a TextView tab in an action bar?

Some other users and I are developing an Android application for the Stack Exchange chat network. We add a tutorial for each action to explain the user interface to the user. However, we ran into a road block.

The textbook library requires a pointer to the view (whether it TextView’s ImageView, whatever) to get the coordinates of the view on the display so that it knows where to draw shadows and more.

We have one action that uses the standard "Tabbed Activity" from Android Studio, so we do not use any custom toolbars .

The action bar looks like this:

enter image description here

And we want to grab a pointer on TextVieweach tab that contains the bookmark title.

So, for example, we want to have access to this TextView:

enter image description here

We were unable to find anything on the Internet on how to do this. It seems relatively easy if you use a custom toolbar , but we do not .

Digging through the AOSP source code, we found a potential way to do this, but the fields we needed access to were either privateeither or inaccessible from the main operation code.

So the question is, how can we grab a pointer to this TextView? Is it possible?

+4
source share
1 answer

, , . Android Device Monitor, , .

:

  • ,

  • ,

, :

ViewGroup viewGroup = (ViewGroup) getWindow().getDecorView();
LinearLayout testb = (LinearLayout) viewGroup.getChildAt(0);
FrameLayout testc = (FrameLayout) testb.getChildAt(1);
ActionBarOverlayLayout testd = (ActionBarOverlayLayout) testc.getChildAt(0);
ActionBarContainer teste = (ActionBarContainer) testd.getChildAt(1);

LinearLayoutCompat testg;

if (getResources().getConfiguration().orientation == ORIENTATION_PORTRAIT)
{
    ScrollingTabContainerView testf = (ScrollingTabContainerView) teste.getChildAt(2);
    testg = (LinearLayoutCompat) testf.getChildAt(0);
}
else //Landscape
{
    Toolbar teste2 = (Toolbar) teste.getChildAt(0);
    ScrollingTabContainerView testf = (ScrollingTabContainerView) teste2.getChildAt(0);
    testg = (LinearLayoutCompat) testf.getChildAt(0);
}

testg.setId(android.R.id.tabcontent);

//String IdAsString = testg.getResources().getResourceName(testg.getId());
//Log.e("TestG", IdAsString);

TutorialStuff.chatsExplorationTutorial(this, testg);

:

enter image description here

+6

Source: https://habr.com/ru/post/1687451/


All Articles