添加导航抽屉时,屏幕变黑

时间:2014-12-22 21:39:33

标签: android screen navigation-drawer

我的申请有问题。完成后: Android 5.0 material design style navigation drawer for KitKat

我的应用无法启动。启动后,屏幕变黑。如果我从布局文件中删除fragment-tag,它就可以了。我有与教程中相同的结构。我在模拟器和Galaxy S2上测试过。

这里有一些代码: 布局/ activity_main.xml中

<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
tools:context=".MainActivity">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"/>

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

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

    </RelativeLayout>

</LinearLayout>

<fragment
    android:id="@+id/left_drawer"
    android:name="example.fragments.NavigationDrawerFragment"
    android:layout_width="@dimen/navigation_drawer_width"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    tools:layout="@layout/fragment_navigation_drawer"
    />

MainActivity:

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

    this.mNavigationDrawerFragment = (NavigationDrawerFragment) this.getSupportFragmentManager().findFragmentById(R.id.left_drawer);
    if (this.mNavigationDrawerFragment == null) {
        this.mNavigationDrawerFragment = new NavigationDrawerFragment();
    }

    // Set up the drawer.
    this.mNavigationDrawerFragment.setUp(R.id.left_drawer, (DrawerLayout) this.findViewById(R.id.drawer_layout));

}

如果我删除:

<fragment
    android:id="@+id/left_drawer"
    android:name="example.fragments.NavigationDrawerFragment"
    android:layout_width="@dimen/navigation_drawer_width"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    tools:layout="@layout/fragment_navigation_drawer"
    />

然后它起作用: - /

0 个答案:

没有答案