我正在尝试实现一个简单的导航抽屉。为此,我使用了 DrawerLayout、ActionBarActivity 和 ActionBarDrawerToggle 的支持库。这就是它目前的样子。问题是抽屉布局打开时导航抽屉切换是可点击的。您可以在这个简短的 youtube 视频中看到这一点。我的问题是如何在抽屉布局打开时阻止切换可点击?下面是我的部分代码
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>