ActionBarDrawerToggle可通过打开的抽屉布局进行点击

时间:2015-02-28 01:47:31

标签: android drawerlayout android-actionbaractivity actionbardrawertoggle

我试图实现一个简单的导航抽屉。为此,我使用了DrawerLayout,ActionBarActivity和ActionBarDrawerToggle的支持库。This is how it currently looks。问题是打开抽屉布局时可以单击导航抽屉切换。您可以在this short youtube video.中看到我的问题是如何在打开抽屉布局时停止切换是否可点击?以下是我的

代码的一部分

MainActivity.java

...
public class MainActivity extends ActionBarActivity {

    private Toolbar toolbar;
    private ActionBarDrawerToggle drawerToggle;

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

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


        DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.my_drawer_layout);
        drawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.ColorPrimaryDark));

        drawerToggle = new ActionBarDrawerToggle(this,drawerLayout,R.string.drawer_open, R.string.drawer_close);

        drawerToggle.syncState();
        drawerLayout.setDrawerListener(drawerToggle);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);

    }
    ...
}

以及此活动的布局

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/my_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <!-- The main content view -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <!-- Your main content -->
        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar"></include>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello_world" />
    </LinearLayout>

    <!-- The navigation drawer -->
    <com.username.navigationdrawertemplate.ScrimInsetsFrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/scrimInsetsFrameLayout"
        android:layout_width="320dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/ColorDrawerBackground"
        android:elevation="10dp"
        android:fitsSystemWindows="true"
        app:insetForeground="#4000">
    </com.username.navigationdrawertemplate.ScrimInsetsFrameLayout>
</android.support.v4.widget.DrawerLayout>

1 个答案:

答案 0 :(得分:1)

android:clickable="true"放入导航抽屉布局