在主要活动中,我得到了一个回收器视图和一个工具栏,以及一个导航抽屉。在加载回收器时,我将它和工具栏也变暗,并阻止导航抽屉在滑动时打开。但是我无法禁用工具栏中的 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
}
}
提前致谢。