마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 앱 개발 질문 있습니다.

0 추천

안녕하세요, 

안드로이드 초짜 개발자 입니다.

 

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>
익명사용자 님이 2016년 2월 4일 질문

1개의 답변

0 추천
 
채택된 답변

NavigationView NavigationView ​= (NavigationView )findViewById(R.id.nav_view);

View HeaderView = NavigationView ​.getHeaderView(0);

익명사용자 님이 2016년 2월 4일 답변
...