2016-06-27 3 views
3

Android 개발을 처음 사용하고 NavigationDrawer를 구현하려고합니다. 이 코드는 잘 작동하지만 전체 화면이 파란색으로 덮여있어 기본 색상이 맞을 것입니다. 도구 모음의 높이를 ?attr/actionBarSize으로 설정했습니다. 도구 모음인지 또는이 문제를 일으키는 다른 개체인지는 알 수 없습니다. 오류의 원인을 설명하여 나중에 피할 수 있도록하십시오.내 안드로이드 응용 프로그램이 primaryColor로 덮여있는 이유

activity_main.xml

<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" 
android:fitsSystemWindows="true" 
tools:openDrawer="start"> 


<include layout="@layout/toolbar" 
    android:id="@+id/my_toolbar"/> 



<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:menu="@menu/activity_main_drawer" /> 

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

도구 모음 .XML

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="?attr/actionBarSize" 
android:background="@color/colorPrimary"> 

</android.support.v7.widget.Toolbar> 

스타일 .XML

<resources> 

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

툴바 제목도 활동 중간에 있습니다. 따라서 툴바 여야합니다. 하지만 도구 모음의 크기를 ActionBarSize로 설정했습니다. 대답하는 사람은 이유를 설명하십시오. Screen shot of my app

그냥 경우에는 너희들은 MainActivity.java

import android.support.design.widget.NavigationView; 
import android.support.v4.widget.DrawerLayout; 
import android.support.v7.app.ActionBarDrawerToggle; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.support.v7.widget.Toolbar; 
import android.view.Menu; 
import android.view.MenuItem; 

공용 클래스 MainActivity가 AppCompatActivity

implements NavigationView.OnNavigationItemSelectedListener{ 

@Override 

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    Toolbar my_toolbar = (Toolbar) findViewById(R.id.my_toolbar); 
    setSupportActionBar(my_toolbar); 
    getSupportActionBar().setTitle(R.string.app_name); 

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
      this, drawer, my_toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
    drawer.addDrawerListener(toggle); 
    toggle.syncState(); 

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 
    navigationView.setNavigationItemSelectedListener(this); 
} 

@Override 

public boolean onCreateOptionsMenu(Menu menu){ 

    getMenuInflater().inflate(R.menu.main_menu, menu); 

    return super.onCreateOptionsMenu(menu); 
} 

@Override 
public boolean onNavigationItemSelected(MenuItem item) { 
    return false; 
} 
} 
+1

우리는 활동의 스크린 샷을 할 수 있습니까? –

+0

NavigationView가 없으면 어떻게됩니까? –

+0

@KevalPatel 스크린 샷을 추가했습니다. – Drilldoge

답변

1

업데이트 귀하의 XML을 확장해야하는 경우

당신은 직접적인 툴바를 보여줍니다 ... 그래서 결과는 툴바를 전체 내용보기로 봅니다. 그래서 모바일 컨텐트보기의 레이아웃을 취해야하며 그 안에 상태 표시 줄과 아래에 표시된 도구 모음을 사용합니다 당신이 당신의 프레임 또는 다른 사람을 .. 사용 아래

<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" 
android:fitsSystemWindows="true" 
tools:openDrawer="start"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
<include layout="@layout/toolbar" 
    android:id="@+id/my_toolbar"/> 
</LinearLayout> 



<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:menu="@menu/activity_main_drawer" /> 

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

코드에 대한 답변은 좋지 않습니다. 무엇이 잘못되었으며 어떻게 고쳐 졌는지 설명하십시오. –

+0

콘텐츠보기를 표시하기 때문에 ..... 이것을 가져야합니다. 콘텐츠가 표시되는 레이아웃 ...... 그렇습니다. 여기에 표시됩니다. 여기에 표시된 것이 있으면 모바일보기 및 서랍 왼쪽에 .. –

+0

@ Er.Arjun saini 문제가 해결되었지만 그 원인을 알고 싶습니다. – Drilldoge

관련 문제