Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 直到我手动向右滑动以打开导航抽屉时,ActionBarDrawerToggle才开始工作。在这之后,它的反应非常好_Android - Fatal编程技术网

Android 直到我手动向右滑动以打开导航抽屉时,ActionBarDrawerToggle才开始工作。在这之后,它的反应非常好

Android 直到我手动向右滑动以打开导航抽屉时,ActionBarDrawerToggle才开始工作。在这之后,它的反应非常好,android,Android,问题: 当我打开应用程序并单击ActionBarDrawerToggle时,它不会打开导航抽屉。然而,当我向右滑动,然后打开和关闭导航抽屉时,在此之后,ActionBarDrawerToggle会很好地重复,就像它应该做的那样,通过打开抽屉 我的HomeScreen.java 我从以下线程尝试了一切:尽管对于那个人,ActionBarDrawerToggle在所有情况下都不起作用,但我的在导航抽屉打开之前都不起作用。从那以后,我的工作就完美了 我试着做的是: 一, 二, 三, 这些对我都不管用

问题: 当我打开应用程序并单击ActionBarDrawerToggle时,它不会打开导航抽屉。然而,当我向右滑动,然后打开和关闭导航抽屉时,在此之后,ActionBarDrawerToggle会很好地重复,就像它应该做的那样,通过打开抽屉

我的HomeScreen.java

我从以下线程尝试了一切:尽管对于那个人,ActionBarDrawerToggle在所有情况下都不起作用,但我的在导航抽屉打开之前都不起作用。从那以后,我的工作就完美了

我试着做的是:

一,

二,

三,

这些对我都不管用

My home_screen.xml


试试这个,或者试着从相对布局中取出工具栏

   <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>
我对你的布局做了一些小修改,希望能对你有所帮助

    <?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/home_screen_main_drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context=".HomeScreen">

    <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <!--Top Layout-->

        <RelativeLayout
                android:layout_width="match_parent"
                android:layout_alignParentTop="true"
                android:layout_height="120dp"
                android:background="@color/blue">

            <android.support.v7.widget.Toolbar
                    android:id="@+id/drawer_menu_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

            <FrameLayout
                    android:id="@+id/drawer_menu_fragment_container"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"/>

            <android.support.v7.widget.Toolbar
                    android:id="@+id/search_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:layout_alignParentBottom="true"
                    android:layout_marginStart="8dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginBottom="10dp"
                    android:background="@drawable/seachbar_homescreen">


                <EditText
                        android:id="@+id/searchHere"
                        android:layout_width="match_parent"
                        android:layout_height="40dp"
                        android:background="@drawable/seachbar_homescreen"
                        android:hint="Search Here"
                        android:textSize="15sp"/>

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


    </RelativeLayout>

    <android.support.design.widget.NavigationView
            android:id="@+id/home_screen_navigation_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentStart="true"
            android:layout_gravity="start"
            app:headerLayout="@layout/home_screen_menu_drawer_header"
            app:menu="@menu/home_screen_menu_drawer"/>


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

您是否使用两个工具栏是的,一个有ActionBarDrawerToggle,放在顶部,另一个有搜索文本视图,从布局底部放置10 dp,即从屏幕顶部放置110 dp当在@Override public boolean OnOptions ItemSelectedMenuItem中单击ActionBarToggle时,我终于能够注册单击{Log.iCLICKED,clicked;drawerLayout.openDrawerGravityCompat.START;return super.onoptionItemSelectedItem;}。在日志中,我可以被单击:已单击,但使用上述命令打开抽屉仍不起作用。是否有人可以帮助我写些什么,而不是抽屉布局。openDrawerGravityCompat.START;在toggle.syncState之后是否有用户“getSupportActionBar.SetDisplayHomeAsupabledTrue;”;我现在添加了它,而不是3菜单行,它显示了一个后退箭头,但同样的问题仍然存在。现在后退箭头实际上像菜单图标一样工作
@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    toggle.syncState();
toggle.setToolbarNavigationClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            drawerLayout.openDrawer(GravityCompat.START);
        }
    });
<?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/home_screen_main_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".HomeScreen">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!--Top Layout-->

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_alignParentTop="true"
            android:layout_height="120dp"
            android:background="@color/blue">

            <android.support.v7.widget.Toolbar
                android:id="@+id/drawer_menu_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <FrameLayout
                android:id="@+id/drawer_menu_fragment_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />


            <android.support.v7.widget.Toolbar
                android:id="@+id/search_toolbar"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_alignParentBottom="true"
                android:layout_marginStart="8dp"
                android:layout_marginEnd="8dp"
                android:layout_marginBottom="10dp"
                android:background="@drawable/seachbar_homescreen"


                <EditText
                    android:id="@+id/searchHere"
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:background="@drawable/seachbar_homescreen"
                    android:hint="Search Here"
                    android:textSize="15sp" />

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


    </RelativeLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/home_screen_navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:layout_gravity="start"
        android:visibility="gone"
        app:headerLayout="@layout/home_screen_menu_drawer_header"
        app:menu="@menu/home_screen_menu_drawer" />


</android.support.v4.widget.DrawerLayout>
}
   <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>
    <?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/home_screen_main_drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context=".HomeScreen">

    <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <!--Top Layout-->

        <RelativeLayout
                android:layout_width="match_parent"
                android:layout_alignParentTop="true"
                android:layout_height="120dp"
                android:background="@color/blue">

            <android.support.v7.widget.Toolbar
                    android:id="@+id/drawer_menu_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

            <FrameLayout
                    android:id="@+id/drawer_menu_fragment_container"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"/>

            <android.support.v7.widget.Toolbar
                    android:id="@+id/search_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:layout_alignParentBottom="true"
                    android:layout_marginStart="8dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginBottom="10dp"
                    android:background="@drawable/seachbar_homescreen">


                <EditText
                        android:id="@+id/searchHere"
                        android:layout_width="match_parent"
                        android:layout_height="40dp"
                        android:background="@drawable/seachbar_homescreen"
                        android:hint="Search Here"
                        android:textSize="15sp"/>

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


    </RelativeLayout>

    <android.support.design.widget.NavigationView
            android:id="@+id/home_screen_navigation_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentStart="true"
            android:layout_gravity="start"
            app:headerLayout="@layout/home_screen_menu_drawer_header"
            app:menu="@menu/home_screen_menu_drawer"/>


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