Android 导航抽屉&x2B;工具栏棒棒糖菜单没有响应

Android 导航抽屉&x2B;工具栏棒棒糖菜单没有响应,android,android-fragments,android-5.0-lollipop,android-drawable,android-toolbar,Android,Android Fragments,Android 5.0 Lollipop,Android Drawable,Android Toolbar,我在开发导航抽屉+工具栏菜单时遇到问题。(全部在棒棒糖上,配有appcompat v21) 问题是,当我在我的主要活动中使用导航抽屉和工具栏时,不会响应侦听器 这是sintax的问题还是其他问题 这是我的项目代码: import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.suppo

我在开发
导航抽屉
+
工具栏
菜单时遇到问题。(全部在棒棒糖上,配有appcompat v21)

问题是,当我在我的主要活动中使用
导航抽屉
工具栏
时,不会响应侦听器

这是sintax的问题还是其他问题

这是我的项目代码:

import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

public class MainActivity extends ActionBarActivity {

    private ActionBarDrawerToggle toogle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final Toolbar toolbar = (Toolbar) findViewById(R.id.tlb_toolbar);
        DrawerLayout drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
        toolbar.setOnMenuItemClickListener(
                new Toolbar.OnMenuItemClickListener(){
                    @Override
                    public boolean onMenuItemClick(MenuItem item){
                        if (item.getItemId()==R.id.info)
                        {
                            getSupportFragmentManager().beginTransaction()
                                    .replace(R.id.container, new fragment_2())
                                    .addToBackStack("1")
                                    .commit();

                            toolbar.getMenu().clear();
                            toolbar.setLogo(null);
                            toolbar.setTitle("F.A.Q");
                            toolbar.inflateMenu(R.menu.menu_second);
                            return true;
                        }
                        if (item.getItemId()==R.id.back) {
                            getSupportFragmentManager().beginTransaction()
                                    .replace(R.id.container, new BlankFragment())
                                    .addToBackStack("2")
                                    .commit();
                            toolbar.getMenu().clear();
                            toolbar.setLogo(R.drawable.ic_launcher);
                            toolbar.setTitle(R.string.app_name);
                            toolbar.inflateMenu(R.menu.menu_main);
                            return true;
                        }
                        if (item.getItemId()==R.id.mes)
                        {
                            getSupportFragmentManager().beginTransaction()
                                    .replace(R.id.container, new fragment_3())
                                    .addToBackStack("3")
                                    .commit();
                            toolbar.getMenu().clear();
                            toolbar.setTitle("Fragments2");
                            toolbar.inflateMenu(R.menu.menu_second);

                        }
                        return false;
                    }
                });
        toolbar.setLogo(R.drawable.ic_launcher);
        toolbar.setTitle(R.string.app_name);
        toolbar.inflateMenu(R.menu.menu_main);
        toogle = new ActionBarDrawerToggle(this, drawerLayout, R.string.open,R.string.close);
        toogle.setDrawerIndicatorEnabled(true);
        drawerLayout.setDrawerListener(toogle);

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new BlankFragment())
                    .commit();
        }
    }
}
我正在布局中使用
Fragment
s。我已经了解到
工具栏中的
片段
s存在一定的故障问题,导航抽屉
布局是否缺少什么?我能做什么

主布局

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/drawer_layout">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

    <include layout="@layout/toolbar_tb" />
    <FrameLayout
        android:layout_below="@+id/tlb_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/container"
        />


    <!-- MAIN CONTENT -->
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/frame5"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity"
        />
        <ListView
            android:id="@+id/lv_menuoverflow"
            android:layout_width="260dp"
            android:layout_gravity="start"
            android:layout_height="fill_parent"
            android:choiceMode="singleChoice"
            android:divider="#2E2E2E"
            android:dividerHeight="2dp"
            android:background="#ffffff"
            android:textColor="#424242"
            android:entries="@array/planetes"
            />
    </LinearLayout>
 </android.support.v4.widget.DrawerLayout>

提前跟你说


附言:对不起我的英语。

您的布局似乎使用了一堆不必要的容器。他们可能会阻塞视图,最终消耗该区域的点击量

尝试以下布局:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/drawer_layout">
    <LinearLayout
        android:id="@+id/container"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <include layout="@layout/toolbar_tb"/>

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

    <ListView
        android:id="@+id/lv_menuoverflow"
        android:layout_width="260dp"
        android:layout_gravity="start"
        android:layout_height="fill_parent"
        android:choiceMode="singleChoice"
        android:divider="#2E2E2E"
        android:dividerHeight="2dp"
        android:background="#ffffff"
        android:textColor="#424242"/>
</android.support.v4.widget.DrawerLayout>


对于这些没有响应的
监听器
您能更具体一些吗?而且,我真的不明白你在这里想干什么。你是想实现一个经典的
导航抽屉
,还是有什么异国情调?第一个问题:听众中的任何人都回答:后退,信息和mes在菜单上,但我按了一下,什么也没发生,而没有抽屉布局的话效果很好。2n问题:它是一个简单的抽屉布局,没有任何特殊样式,只有一个列表视图。这是一个例子:是的,它几乎解决了所有问题,但我需要2个片段来使用片段事务。我使用这个发行版是因为我需要一个框架布局,它必须在工具栏下。随着您提出的发行版,碎片填充了所有应用程序布局,吃掉了工具栏。@MarcS我明白了。在我更新的答案中尝试布局。只需确保
toolbar\u tb
root视图具有固定或
wrap\u内容
height。是的!就这样。我只放错了2个框架布局,而只需要1个。非常感谢。