Кнопка гамбургера на панели навигации не отвечает при первом запуске.
Сдвиньте влево-> вправо, чтобы открыть панель навигации, и после того, как я открою ее, сдвинув кнопку гамбургера, внезапно начнёт работать ..
Я почти уверен, что это что-то с порядком расположения, но я не могу отследить его.
Я покажу вам, что я сделал с кодом, а также с XML.
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
}
};
drawer.addDrawerListener(toggle);
toggle.syncState();
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_home) {
} else if (id == R.id.nav_favorites) {
pozoviFavorites();
} else if (id == R.id.nav_playlists) {
} else if (id == R.id.nav_logout) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
<?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"
android:fitsSystemWindows="true"
tools:openDrawer="start"
>
<FrameLayout
android:id="@+id/popularFrameLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="wrap_content"
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:background="@color/red"
/>
<com.miguelcatalan.materialsearchview.MaterialSearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:textColorHint="#FFFFFF"
android:visibility="visible"
app:searchBackIcon="@drawable/ic_action_navigation_arrow_back_inverted"
app:searchBackground="@color/red"
app:searchCloseIcon="@drawable/ic_action_navigation_close_inverted"
app:searchSuggestionBackground="@color/red"
app:searchSuggestionIcon="@drawable/ic_suggestion"
/>
<ListView
android:id="@+id/list_suggest"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/search_view"
android:background="@color/black"
android:divider="@null"
android:dividerHeight="0dp"
android:orientation="vertical"
android:visibility="gone" />
</RelativeLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/activity_main_swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginTop="7dp"
android:layout_marginRight="7dp">
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:choiceMode="singleChoice"
android:divider="@null"
android:dividerHeight="7dp"
android:orientation="horizontal"
android:visibility="visible" />
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
</FrameLayout>
<TextView
android:id="@+id/empty_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:gravity="center"
android:textAppearance="?android:textAppearanceMedium" />
<ProgressBar
android:id="@+id/loading_indicator"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminateDrawable="@drawable/my_border4"
android:visibility="gone"
/>
<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:visibility="gone"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>