I wonder if it is possible to get a decorViews child. For example if I have a decorView object and I know that the child of the decorView is a FrameLayout, is there someway for me to get the FrameLayout object just by using its parent?
Obviously I could use getViewById() in the traditional way, but if I only want to use the parent object, is it possible to get the FrameLayout object?
Thanks,
Are you talking about object inheritance?
If that is the case, then it is simple: Cast it.
Assuming you have a class “Foo” which is an ancestor-class of “Bar” (in other words: Bar is a “child” of Foo), then take this example:
So, adapting this to your question:
or:
You should protect the block making this call though as this will throw a
ClassCastExceptionif the instance returned bygetDecorViewis not aFrameLayout(or a (in)direct subclass of it). Simply add a try/catch block, or add athrowingdeclaration to the method containing this line. Whatever suits you best.