Answer the question
In order to leave comments, you need to log in
How to get root layout in android app?
Actually the question is in the title.
There is an activity: activity_main.xml . Tried to get like this: findViewById(R.layout.activity_main);
I get null .
Who knows, tell me what I'm doing wrong?
Answer the question
In order to leave comments, you need to log in
The findViewById method looks for a View by its ID. You are trying to search by layout ID. It won't work.
You need to assign an ID to your root element in the template and search by that ID. Like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/simple_id">
</LinearLayout>
findViewById(R.id.simple_id);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question