在主要活动中,我得到了一个Recycler View和一个工具栏,以及一个导航抽屉。在加载Recycler的同时,我也将它和工具栏变暗,并在滑动时阻止导航抽屉打开。但是我无法在工具栏中禁用DrawerToggle,但我想要显示它。我尝试了这两个选项,但都不起作用:
mDrawerLayout.setDrawerListener(null);
mLeftDrawerToggle.setToolbarNavigationClickListener(null);
我怎样才能实现这一目标?这是我的主要布局:
<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">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Toolbar -->
<include android:id="@+id/appbar"
layout="@layout/toolbar"> </include>
</FrameLayout>
<FrameLayout
android:id="@+id/main_frame_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ProductsUI">
<!-- Recycler Grid -->
<android.support.v7.widget.RecyclerView
android:id="@+id/grid_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:clipToPadding="false"
android:paddingTop="?attr/actionBarSize"/>
<!-- Fondo para oscurecer la pantalla -->
<ImageView
android:id="@+id/darken_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:visibility="gone"
android:alpha="0.6"/>
<!-- LoaderView -->
<com.greenfrvr.rubberloader.RubberLoaderView
android:id="@+id/rubber_loader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"
app:loaderExtraColor="@color/colorAccent"
app:loaderPrimeColor="@color/colorAccent"
app:loaderSize="medium"
/>
<!-- Texto de error -->
<TextView
android:id="@+id/error_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/error_message"
android:textSize="20sp"
android:textColor="@color/colorText" />
<TextView
android:id="@+id/nodata_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/action_bar_height"
android:layout_gravity="center_horizontal"
android:visibility="gone"
android:paddingTop="@dimen/action_bar_height"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/nodata_message"
android:textSize="20sp"
android:textColor="@color/colorText" />
</FrameLayout>
<include layout="@layout/left_navigation_drawer"/>
</android.support.v4.widget.DrawerLayout>
更改主要布局的方法:
protected void onPreExecute()
{
_loading(true);
}
protected void onPostExecute( Void unused )
{
if ( error != null )
{
_error(true);
} else {
try {
...
_loading(false);
...
}
} // onPostExecute
private void _loading( boolean loading )
{
if ( ! loading )
{
mRubberLoader.setVisibility(View.GONE);
mDarkenScreenView.setVisibility(View.GONE);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
} else {
mRubberLoader.setVisibility(View.VISIBLE);
mRubberLoader.startLoading();
mDarkenScreenView.setVisibility(View.VISIBLE);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
mDrawerLayout.setDrawerListener(null); // NOT WORKING
mLeftDrawerToggle.setToolbarNavigationClickListener(null); // NOT WORKING
}
}
提前致谢。