2016-06-07 3 views
0

현재 툴바 및 DrawerLayout을 사용하여 Android 앱을 개발 중입니다. 주요 내용은 다른 모양, 텍스트를 그릴 수있는 사용자 지정 SurfaceView입니다. 왼쪽 메뉴는 NavigationView이며 도구 상자로 사용됩니다 (왼쪽에서 그리려는 항목을 선택하고 SurfaceView에서 그립니다). 한 가지를 제외하고는 모든 것이 잘 작동합니다. 도구 모음을 클릭하거나 화면의 왼쪽에서 밀어 왼쪽 메뉴를 열려고 할 때 항목이 보이지 않습니다. 그리고 어떤 항목 (보이지 않음)을 클릭하지는 않지만 보이지 않습니다. 보이지 않는 항목을 클릭하면 메뉴가 정상적으로 작동하는 경우에만 문제가 해결됩니다. 나는 상태 표시 줄을 숨기고 기본 액션 바 제거하기 위해 사용자 지정 테마를 사용하고 있습니다 : 스크린 샷은 여기안드로이드 - 처음 열 때 DrawerLayout 및 툴바가 표시되지 않습니다.

<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.NoActionBar"></style> 

<style name="ColladiaTheme" parent="AppBaseTheme"> 

    <!-- Remove action bar --> 
    <item name="android:windowActionBar">false</item> 
    <item name="android:windowNoTitle">true</item> 

    <!-- Remove status bar --> 
    <item name="android:windowFullscreen">true</item> 
    <item name="android:windowContentOverlay">@null</item> 

    <!-- Material theme --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 

</style> 

입니다 : 여기

Menu open but not visible

Menu visible after clicking an item

<?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:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <com.ia04nf28.colladia.DrawColladiaView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/draw_view" /> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_height="?attr/actionBarSize" 
      android:layout_width="?attr/actionBarSize" 
      android:minHeight="?attr/actionBarSize" 
      android:background="?attr/colorPrimary"> 
     </android.support.v7.widget.Toolbar> 

    </FrameLayout> 

    <!-- Left navigation menu --> 
    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="?attr/actionBarSize" 
     android:layout_height="match_parent" 
     android:layout_marginTop="?attr/actionBarSize" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="false" 
     app:menu="@menu/nav_view_items" > 
    </android.support.design.widget.NavigationView> 

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

그리고 활동 코드 :

당신의 서랍 이제까지 개방되는 위치

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 

    // This will toggle the drawer if android.R.id.home is clicked 
    if(drawerToggle.onOptionsItemSelected(item)) { 
     return true; 
    } 

    // Handle any other menu item selections... 

    return super.onOptionsItemSelected; 
} 

는 솔직히 말해서, 나는 보이지 않는 : 당신이 onBackPressed 대신 onOptionsItemSelected를 재정의해야처럼210

은}

+0

아무것도 당신의 XML에 잘못된 것으로 나에게 점프하지, 당신의 활동 코드와 함께 할 수있는 뭔가가있을 수 있습니다. – Bryan

+0

@ 브라이언, 내 질문을 편집하고 내 활동 코드를 추가했습니다 – Bash

답변

0

것 같습니다. 그래도 왼쪽 가장자리에서 스 와이프에 응답해야합니다. 이 코드는 android.R.id.home (백/메뉴 버튼)을 클릭하면 토글되도록 설정합니다.

+0

불행히도 이것은 작동하지 않습니다. 나는 다른 장치들과 안드로이드 에뮬레이터로 시험해 보았고 그것들이 잘 작동하고있는 것처럼 보입니다. 내 휴대 전화와 관련이있는 것 같아 ... – Bash

+0

@Bash 아, 그들은 안드로이드의 다른 버전을 실행하고 있습니까? 이전 버전에는 버그가있을 수 있습니다. – Bryan

+0

휴대 전화가 Android 5.0 (Lollipop) 및 Android 4.1.1의 에뮬레이터에서 실행 중입니다. 에뮬레이터에서 작동하지만 휴대 전화에서는 작동하지 않습니다. – Bash

0

좋아, 문제는 setUpDrawerContent 및 selectDrawerItem에 있습니다. 기본적으로 버튼을 설정하려고하지만 navigationItemSelectedListener를 대신 추가합니다. 이런 경우가 발생합니다. 모든 것을 준비한 다음 수신기를 추가합니다. 탐색 서랍에서 항목을 클릭 할 때까지 아무 일도 일어나지 않습니다. 뭔가를 클릭하면 클릭 리스너가 실행되고 서랍 항목이 만들어집니다.

비행 중에 요소를 만들려고하지만 보이지 않는 단추를 눌렀을 때만이 생성이 시작됩니다.

selectDrawerItem의 스위치의 기본 경우에서 setUpDrawerContent로 코드를 이동하고 navigationItemSelectedListener를 설정하기 전에 몇 줄을 놓으십시오. 또한 모든 버튼을 만들거나, for 루프 또는 뭔가를 사용하여 메뉴 항목을 미리 만들어야합니다. 이처럼

:

public void setUpDrawerContent(NavigationView nav) 
{ 
    /* 
    //for loop here to add your menu items 
    Element newElement = ElementFactory.createElement(getApplicationContext(), item.getTitle().toString()); 

    if (newElement != null) 
     colladiaView.insertNewElement(newElement); 
    */ 
    nav.setNavigationItemSelectedListener(
      new NavigationView.OnNavigationItemSelectedListener() { 
       @Override 
       public boolean onNavigationItemSelected(MenuItem item) { 
        selectDrawerItem(item); 
        return true; 
       } 
      } 
    ); 
} 

public void selectDrawerItem(MenuItem item) 
{ 
    switch(item.getItemId()) 
    { 
     case R.id.nav_home: 
      Intent intent = new Intent(getApplicationContext(), LoginActivity.class); 
      startActivity(intent); 
      break; 
     // more cases goes here to handle each menu item clicks 
     default: 
      //pop a Toast message or something about not existing function 
      drawer.closeDrawers(); 
      break; 
    } 
} 
+0

ElementFactory 부분은 메뉴에서 사용할 수있는 항목과 관련이 없습니다.navigationView에서 사용할 수있는 항목은 다음 레이아웃을 사용하여 설정됩니다. app : menu = "@ menu/nav_view_items" – Bash

관련 문제