Los botones de la barra de herramientas no responden al tacto cuando está abierto un cajón de navegación

Estoy trabajando en una versión de diseño de material de mi aplicación usando las librerías appcompat v7, y he llegado a un problema con el cajón de navegación. Cuando se abre, los botones de la barra de herramientas de diseño de materiales dejan de funcionar – cualquier toque fuera del cajón de navegación sólo cierra el cajón. Un siguiente es un gif de lo que quiero decir

El gif http://images.rymate.co.uk/images/83JXi1X.png

Aquí está el diseño xml que estoy usando para la actividad:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- The main content view --> <FrameLayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.Toolbar android:id="@+id/action_toolbar" android:layout_height="wrap_content" android:layout_width="match_parent" android:minHeight="?attr/actionBarSize" android:background="?attr/colorPrimary" app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" android:elevation="4dp" /> <FrameLayout android:id="@+id/note_list_container" android:layout_marginTop="?attr/actionBarSize" android:layout_width="match_parent" android:layout_height="match_parent" /> <net.rymate.notes.ui.FloatingActionButton android:id="@+id/fabbutton" android:layout_width="72dp" android:layout_height="72dp" android:layout_gravity="bottom|right" android:layout_marginBottom="16dp" android:layout_marginRight="16dp" /> </FrameLayout> <!-- The navigation drawer --> <LinearLayout android:id="@+id/left_drawer" android:layout_width="300dp" android:layout_marginTop="?attr/actionBarSize" android:layout_height="match_parent" android:layout_gravity="start" android:orientation="vertical"> <ListView android:id="@+id/cat_list" android:layout_width="match_parent" android:layout_height="match_parent" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" android:background="?catBackColour" /> </LinearLayout> </android.support.v4.widget.DrawerLayout> 

Y aquí está el código onCreate que inicializa el cajón y la barra de herramientas.

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ROBOTO_LIGHT = Typeface.createFromAsset(this.getAssets(), "Roboto-Light.ttf"); ROBOTO_LIGHT_ITALICS = Typeface.createFromAsset(this.getAssets(), "Roboto-LightItalic.ttf"); setContentView(R.layout.activity_notes); if (findViewById(R.id.note_container) != null) { // The detail container view will be present only in the // large-screen layouts (res/values-large and // res/values-sw600dp). If this view is present, then the // activity should be in two-pane mode. mTwoPane = true; // In two-pane mode, list items should be given the // 'activated' state when touched. FragmentManager fm = getSupportFragmentManager(); //list.setActivateOnItemClick(true); } if (!mTwoPane) { final FloatingActionButton mFab = (FloatingActionButton) findViewById(R.id.fabbutton); mFab.init(Color.parseColor("#1e90ff")); mFab.setFabDrawable(getResources().getDrawable(R.drawable.ic_action_new)); mFab.showFab(); mFab.setOnClickListener(this); list = new NotesListFragment(mFab); } else { list = new NotesListFragment(); } Toolbar toolbar = (Toolbar) findViewById(R.id.action_toolbar); setSupportActionBar(toolbar); getSupportFragmentManager().beginTransaction() .replace(R.id.note_list_container, list) .commit(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // the layout mDrawerLinear = (LinearLayout) findViewById(R.id.left_drawer); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); mDrawerLayout.setScrimColor(getResources().getColor(android.R.color.transparent)); mDrawerToggle = new ActionBarDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ toolbar, /* toolbar */ R.string.drawer_open, /* "open drawer" description */ R.string.drawer_close /* "close drawer" description */ ) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getSupportActionBar().setTitle("Rymate Notes"); supportInvalidateOptionsMenu(); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getSupportActionBar().setTitle("Categories"); supportInvalidateOptionsMenu(); } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); pref = getSharedPreferences("rymatenotesprefs", MODE_PRIVATE); mDrawerList = (ListView) findViewById(R.id.cat_list); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); mDbHelper = new NotesDbAdapter(this); mDbHelper.open(); if (mDbHelper.fetchAllNotes().getCount() == 0) { IntroFragment fragment = new IntroFragment(); getSupportFragmentManager().beginTransaction() .replace(R.id.note_list_container, fragment) .commit(); } getCategories(); // calls a function which populates the listview } 

¿Hay alguna manera de arreglar esto?

Parece que el evento táctil es robado por la sombra del cajón, es decir, DrawerLayout mantiene la interceptación de los eventos táctiles, porque Toolbar forma parte de la vista de contenido, a diferencia de la ActionBar está encima de la vista de decoración.

Posible trabajo alrededor es interceptar el evento táctil:

Si está entre 0 (arriba) y la altura de la Toolbar (abajo), envíe el evento directamente al objeto de la Toolbar . De lo contrario, mantenga el comportamiento normal.

¿Es el mismo caso para los clics de conmutación de cajón?

Resulta Nikola Despotoski tenía la idea correcta – el evento táctil fue robado por el DrawerLayout. Sin embargo, en lugar de interceptar el evento táctil, sólo ajusté el diseño de la actividad de la siguiente manera:

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/layout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <android.support.v7.widget.Toolbar android:id="@+id/action_toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorPrimary" android:elevation="4dp" android:minHeight="?attr/actionBarSize" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" /> <android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="?attr/actionBarSize" > <!-- The main content view --> <FrameLayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:id="@+id/note_list_container" android:layout_width="match_parent" android:layout_height="match_parent"/> <net.rymate.notes.ui.FloatingActionButton android:id="@+id/fabbutton" android:layout_width="72dp" android:layout_height="72dp" android:layout_gravity="bottom|right" android:layout_marginBottom="16dp" android:layout_marginRight="16dp" /> </FrameLayout> <!-- The navigation drawer --> <LinearLayout android:id="@+id/left_drawer" android:layout_width="300dp" android:layout_height="match_parent" android:layout_gravity="start" android:orientation="vertical"> <ListView android:id="@+id/cat_list" android:layout_width="match_parent" android:layout_height="match_parent" android:background="?catBackColour" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" /> </LinearLayout> </android.support.v4.widget.DrawerLayout> </FrameLayout> 

Esto tiene el efecto deseado de permitir que los eventos táctiles se registren en la Toolbar lugar de la DrawerLayout.

  • ¿Cuál es la diferencia entre la barra de acción y la recién introducida barra de herramientas?
  • FAB animación de transición que funciona debajo de Android L?
  • Creación de un botón de acción flotante con menús de subacción animados
  • Fragmento de error: tipos incompatibles, requiere android.app.fragment pero encontró activity.messagefragment
  • Estilizar los botones de material en Android v21
  • El título de la barra de aplicaciones no se muestra en android 5.0 y superior
  • ¿Cómo imitar el estilo de diseño de material levantado estilo de botón, incluso para pre-Lollipop (menos los efectos especiales)?
  • Flecha de flecha hacia arriba que superpone el título de la barra de herramientas
  • Tablas de material de Android 5.0 con barra de herramientas
  • No funciona Notifydatasetchange en RecyclerView con selección de centro Horizontal Scrollview?
  • Cambio de Android Color de sombra de elevación de material
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.