안녕하세요,
안드로이드 초짜 개발자 입니다.
Navigation Drawer Acivity 로 신규 프로젝트를 만들어서
개발을 진행중인데요,
여기서 궁금한게 있어서요.
기본 구조를 보면 layout 에
1. activity_main.xml
2.app_bar_main.xml
3.content_main.xml
4.nav_header_main.xml
이렇게 있는데요.
MainActivity 에서 setContentView(R.layout.activity_main);
이렇게 해주면 findViewId 로 nav_header_main.xml 에 있는걸 가져오면 null로 넘어오네요..
activity_main, app_bar_main, content_main 에 있는 것들은 잘 가져오는데
nav_header_main 에 있는걸 가져오면 null 이 되서요...
activity_main 는
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drawer_layout"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer"
/>
</android.support.v4.widget.DrawerLayout>