2017-02-26 10 views
0

내 탐색 창에 머리글을 추가하려고합니다. 나는 안드로이드 스튜디오 초보자 다. 그래서 어떤 팁이 나를 도왔을 것이다.탐색 서랍 헤더가 내용 위에 있습니까?

문제는이 헤더가 내 탐색 창 itens 위에있어 문제가 생겼다. 내 탐색 창 itens가 보이지 않는다.

이 헤더를 올바르게 추가하려면 어떻게해야합니까? 또한, 내 textview 콘텐츠가 표시되지 않습니다, 왜?

<?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" 
    tools:context="com.sk.mf.UserAreaActivity" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#fff" 
    android:id="@+id/drawerLayout"> 


    <FrameLayout 
     android:layout_height="wrap_content" android:layout_width="wrap_content" 
     android:id="@+id/content_frame"> 
    </FrameLayout> 


    <android.support.design.widget.NavigationView 
     android:id="@+id/navigation" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     app:menu="@layout/navigation_menu" 
     android:layout_gravity="start"> 



     <RelativeLayout 
      android:orientation="vertical" android:layout_width="match_parent" 
      android:layout_height="100dp" 
      android:background="@color/colorPrimary"> 

      <TextView 
       android:text="TextView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerVertical="true" 
       android:layout_centerHorizontal="true" 
       android:id="@+id/nh_User" 
       android:textSize="24sp" 
       android:textColor="#ffffff" /> 

     </RelativeLayout> 






    </android.support.design.widget.NavigationView> 



</android.support.v4.widget.DrawerLayout> 

답변

1

헤더 NavigationView의 태그의 헤더 만들기 : 당신의 layout/nav_header.xml

<android.support.design.widget.NavigationView 
    android:id="@+id/navigation_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:background="@color/white" 
    app:headerLayout="@layout/nav_header" //layout of Header 
    app:itemIconTint="@color/colorPrimary" 
    app:menu="@menu/menu_navigation" /> 

을 :

NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view); 
View header = navigationView.getHeaderView(0); //get the header view 
TextView text = (TextView) header.findViewById(R.id.nh_User); 
text.setText("Hello"); 
: 헤더 레이아웃 콘텐츠 사용에 액세스하려면 헤더 내용

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="190dp" 
    android:orientation="vertical"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@android:color/transparent" 
     android:scaleType="fitXY" 
     android:src="@drawable/drawer_header" /> 
</LinearLayout> 

를 추가

+0

그쪽으로 너 친구 야! 그래서 내 textview nav_header.xml 너무있을 것이라고? 어떻게하면 헤더 내에서 텍스트 뷰에 텍스트를 추가 할 수 있습니까? 이 XML을위한'setContentView (R.layout.base_activity);와이 텍스트 뷰에 텍스트를 추가하기위한'nh_User.setText (Username);'이 있지만 nav_header.xml을 생성하기 때문에'nh_User'를 더 이상 참조 할 수 없기 때문에 ... –

+1

답변을 편집했습니다. @RickJoe – rafsanahmad007

+0

대단히 감사합니다! –