2016-11-03 8 views
0

ナビゲーションドロワーにリンクされたフラグメントにカスタムのツールバードロップダウンメニューを追加しようとしていますツールは裸の別の半分のナビゲーション・ドロワのように見えます。 はあなただけstyles.xmlリソースファイルにあなたが知っているようにHERESに完全にfuctioningナビゲーション引き出し the fully fuctioning Navigation drawerフラグメント内のツールバーは、ナビゲーションドロワーのように見えます。ドロップダウンメニューを使用して通常のツールバーにする方法

を混同されることはありませんちょうどのでめちゃめちゃアップツールバーのドロップダウンメニュー the messed-up toolbar drop-down menu

の写真を聞きます私はここfragmantのレイアウトと呼ばれるfragment_student.xmlだ<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

を入力して、デフォルトのツールバーを削除

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.isaacdixon.navigation.StudentFragment"> 

    <android.support.v7.widget.Toolbar 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     android:theme="?attr/actionBarTheme" 
     android:minHeight="?attr/actionBarSize" 
     android:id="@+id/toolbar_student" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="Student" 
     android:gravity="center" 
     android:textSize="35dp" 
     android:textStyle="bold"/> 



    <android.support.design.widget.NavigationView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/toolbar_view" 
     app:menu="@menu/student_menu" 
     > 

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


</FrameLayout> 

は、ここでそのドロップダウンツールバーここ

  • <item android:id="@+id/student_tb_settings" 
        android:title="Settings" 
        android:icon="@mipmap/ic_person_black_24dp"/> 
    
    <item android:id="@+id/student_tb_other" 
        android:title="Other" 
        android:icon="@mipmap/ic_settings_black_24dp"/> 
    

ためStudentFragment.javaファイル

package com.example.isaacdixon.navigation; 


import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 


/** 
* A simple {@link Fragment} subclass. 
*/ 
public class StudentFragment extends Fragment { 


    public StudentFragment() { 
     // Required empty public constructor 
    } 


    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     return inflater.inflate(R.layout.fragment_student, container, false); 
    } 

} 
だ、fragment_student.xmlメニューです

答えて

1

問題はあなたがすべて間違っているということです。コンテンツビューとナビゲーションビューを含むトップビューとしてDrawerLayoutを持つ必要があります。

私は次のチュートリアルを通過することができことをお勧め:

https://guides.codepath.com/android/Fragment-Navigation-Drawer

+0

申し訳ありませんが、あなたが、私は(私はすでにことをやった)、私は、ナビゲーションの引き出しを作るつもりはないよ理解していませんプルダウンメニューでツールバーを作成しようとしています –

関連する問題