मैं अगर मैं सही ढंग से अपने अनुप्रयोग के अपने विवरण समझ में आ यकीन नहीं है के लिए अलग से उपकरण पट्टी को लागू करने की है, लेकिन मैं हाल ही में किया था कि मैं क्या लगता है कि आप वर्णित हैं। मेरा गतिविधि लेआउट एक एकल टूलबार और नीचे एक फ्रेमलेआउट के साथ एक कोऑर्डिनेटरलेआउट/ऐपबार लेआउट के साथ एक ड्रॉवरलाउट था। Menu.xml में सभी टुकड़ों के लिए मेरे टूलबार में आवश्यक सभी आइटम शामिल थे। एनवी मेनू में क्लिक किए गए आइटम फ्रेमलेआउट में टुकड़े स्वैप करेंगे। मेरे onNavigationItemSelected() टुकड़े बाहर स्वैप और backstack को संभालने के लिए इस पद्धति पर कहा जाता है:
public void switchView(int id, int optArg) {
if (currentView != id) {
currentView = id; //currentView keeps track of which fragment is loaded
FragmentTransaction transaction = getFragmentManager().beginTransaction();
//Fragment contentFragment is the current fragment in the FrameLayout
switch (id) {
case 0: //menu item 1
contentFragment = new Nav_Item1_Fragment();
transaction.replace(R.id.fragment_container, contentFragment, "");
break;
case 1: //menu item 2
contentFragment = new Nav_Item2_Fragment();
transaction.replace(R.id.fragment_container, contentFragment, "");
break;
case 2: //menu item 3
contentFragment = new Nav_Item3_Fragment();
transaction.replace(R.id.fragment_container, contentFragment, "");
break;
}
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack
// transaction.replace(R.id.fragment_container, contentFragment);
transaction.addToBackStack(null);
// Commit the transaction
transaction.commit();
}
}
और प्रत्येक खंड के onPrepareOptionsMenu() मैं setVisible() में छिप/कि टुकड़ा से संबंधित उपकरण पट्टी में मेनू आइटम दिखाया। प्रत्येक आइटम में मेनू आइटम के ऑनक्लिक विशेषता द्वारा इंगित गतिविधि में एक विधि थी जो जानता था कि यह किस टुकड़े से था और इसके लिए क्या विचार पारित किए गए थे।
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
गतिविधि xml::
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
...>
<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"
.../>
</android.support.v4.widget.DrawerLayout>
app_bar_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
...>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:gravity="top"
.../>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/fragment_container"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
तो
दराज() गतिविधि का तो जैसे एक ActionBarDrawerToggle साथ onCreate में सेटअप था ... एक नव मेनू, एक ऐप/टूल बार, एकाधिक टुकड़े
क्या आपको कोई समाधान मिला है? –
कोई समाधान नहीं मिला – alphanso