Ich verwende Navigation Drawer
und die ActionBarDrawerToggle
wird synchronisiert, wenn ich die Schublade durch Schieben öffne, aber wenn ich auf Toolbar
Icon klicke, öffnet sich die Schublade nicht. Was ist falsch in meinem Code.Verknüpfen der Navigationsleiste mit der Werkzeugleistenschaltfläche
actionBarDrawerToggle = new ActionBarDrawerToggle(Main2Activity.this, drawerLayout, toolbar, R.string.drawer_open, R.string.close_drawer) {
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
};
drawerLayout.setDrawerListener(actionBarDrawerToggle);
drawerLayout.post(new Runnable() {
@Override
public void run() {
actionBarDrawerToggle.syncState();
}
});
Dinge, die ich versuchen, so zu:
actionBar.setDisplayHomeAsUpEnabled(true);
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
drawerLayout.openDrawer(Gravity.START);
return true;
}
return super.onOptionsItemSelected(item);
}
Das ist mein Layout, die ich verwenden. Ich habe NavigationView
und Schublade Layout.
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".Main2Activity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.ActionBar"
app:theme="@style/ToolbarColoredIcon" />
<include layout="@layout/content_main2" />
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start">
<LinearLayout
android:id="@+id/nav_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--header-->
<include
android:id="@+id/header"
layout="@layout/nav_header"
/>
<!--items-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/dp20">
<include
android:id="@+id/nav_menue_item_home"
layout="@layout/nav_menue_item" />
<include
android:id="@+id/nav_menue_item_settings"
layout="@layout/nav_menue_item" />
<include
android:id="@+id/nav_menue_item_more_apps"
layout="@layout/nav_menue_item" />
<include
android:id="@+id/nav_menue_item_rate_us"
layout="@layout/nav_menue_item" />
<include
android:id="@+id/nav_menue_item_privacy_policy"
layout="@layout/nav_menue_item" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e3e4e3"
android:gravity="bottom"
android:orientation="vertical">
<com.google.android.gms.ads.NativeExpressAdView
android:id="@+id/adViewNative"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
ads:adSize="@string/native_sm_ad_size"
ads:adUnitId="@string/native_sm_ad_unit_id" />
</LinearLayout>
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
so wenden Sie sich bitte, wo ist jetzt Problem?
Dank an alle habe ich mein Problem zu lösen. Das Problem ist nicht wirklich im Code, aber Problem ist im Layout, wo ich einen TabHost hinzufüge, der Symbolleiste für Klicken nicht erlaubt, so ist dieses tatsächliche Problem.
Wenn 'toolbar' nicht null ist, dann sind der' setDisplayHomeAsUpEnabled() 'Aufruf und die' onOptionsItemSelected() 'Methode nicht notwendig mit diesem' ActionBarDrawerToggle' Konstruktor. Möglicherweise stimmt etwas mit dem Layout nicht. Sie haben z. B. eine 'View', die die' Toolbar' abdeckt. –