材料设计抽屉式导航栏不滑出 [英] Material design navigation drawer not sliding out

查看:271
本文介绍了材料设计抽屉式导航栏不滑出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跟着这个<一个href=\"http://stackoverflow.com/questions/26476837/android-5-0-material-design-style-navigation-drawer-for-kitkat\">StackOverflow帖子的指导和管理,以获得 ActionBarDrawerToggle 及其动画工作。然而,没有导航抽屉滑出。这是为什么?

I followed this StackOverflow post's instructions and managed to get the ActionBarDrawerToggle and its animation working. However, no navigation drawer slides out. Why is that?

activity_main.xml中:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"
tools:ignore="MergeRootFrame"
android:fitsSystemWindows="true" >

<include layout="@layout/toolbar" />

<it.neokree.materialtabs.MaterialTabHost
    android:id="@+id/materialTabHost"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    app:textColor="#FFFFFF"
    app:primaryColor="#33B5E5"
    app:accentColor="#FFFFFF" />

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Main layout -->
    <FrameLayout
        android:id="@+id/main_fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- Nav drawer -->
    <fragment
        android:id="@+id/nav_drawer"
        android:name="com.wsandhu.conjugation.DrawerFragment"
        android:layout_width="@dimen/drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="left|start" />
</android.support.v4.widget.DrawerLayout>
</LinearLayout>

这里的code在的onCreate()方法的 MainActivity.java

ActionBarDrawerToggle mDrawerToggle;
DrawerLayout mDrawerLayout;

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

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.app_name, R.string.app_name);
    mDrawerLayout.setDrawerListener(mDrawerToggle);

...

    if (savedInstanceState == null) {
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                getSupportFragmentManager().beginTransaction()
                        .add(R.id.container, new MainFragment())
                        .commit();
            }
        });
    }

...

}

我有一个 DrawerFragment 类和它的XML文件,但正如我所说,没有滑出时,我点击了 ActionBarDrawerToggle 在我的应用程序。切换动画完美。

I have a DrawerFragment class and its XML file, but as I said, nothing slides out when I tap the ActionBarDrawerToggle in my app. The toggle animates perfectly.

这需要在其他职位说在我的 MainActivity ,在的onCreate()方法。我真的不知道还有什么补充,我不知道这一点。

The five methods that needed to be overrided as stated in the other post are in my MainActivity, after the onCreate() method. I really don't know what else to add, I can't figure this out.

先谢谢了。

推荐答案

我不明白 DrawerLayout ,部分原因是的 jpardogo 的答案。

I did not understand DrawerLayout, in part due to jpardogo's answer.

我需要设置我的活动的XML文件正确的主要内容框架,所以我做了 android.support.v4.widget.DrawerLayout 文件的根元素,并把我的活动的的LinearLayout 抽屉式导航栏上面的片段元素。这里是正确的,工作code:

I needed to set the proper main content frame in my activity's XML file, so I made android.support.v4.widget.DrawerLayout the root element of the file, and put my activity's LinearLayout above the navigation drawer fragment element. Here is the proper, working code:

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Main layout -->
<LinearLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity"
    tools:ignore="MergeRootFrame"
    android:fitsSystemWindows="true" >

    <include layout="@layout/toolbar" />

    <it.neokree.materialtabs.MaterialTabHost
        android:id="@+id/materialTabHost"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        app:textColor="#FFFFFF"
        app:primaryColor="#33B5E5"
        app:accentColor="#FFFFFF" />

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

<!-- Nav drawer -->
<fragment
    android:id="@+id/nav_drawer"
    android:name="com.wsandhu.conjugation.DrawerFragment"
    android:layout_width="@dimen/drawer_width"
    android:layout_height="match_parent"
    android:layout_gravity="left|start" />

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

这将有助于这个比较在原岗位的XML文件。希望这有助于。

It would help to compare this to the XML file in the original post. Hope this helps.

这篇关于材料设计抽屉式导航栏不滑出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆