El evento OnClick en TextView detiene RippleEffect en CardView

Tengo un TextView dentro de un CardView. Al activar el efecto de ondulación de Lollipop en el CardView añadiendo un evento OnClick y añadiendo la propiedad:

android:foreground="?android:attr/selectableItemBackground"

Funciona bien. Pero después de agregar un evento OnClick al TextView, el efecto de ondulación sigue apareciendo cuando hago clic fuera del TextView, pero no se mostrará al hacer clic en el área TextView.

¿Hay lejos de mostrar la ondulación, incluso cuando hago clic en el TextView?

Aquí está xml:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <android.support.v7.widget.CardView android:id="@+id/news_card" android:foreground="?android:attr/selectableItemBackground" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/text" android:text="Test String" android:layout_width="match_parent" android:layout_height="wrap_content"/> </android.support.v7.widget.CardView> </RelativeLayout> 

Aquí está el código:

 protected void onCreate (Bundle savedInstanceState) { super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); View v = findViewById (R.id.news_card); v.setOnClickListener (new View.OnClickListener () { @Override public void onClick (final View v) { } }); View textView = findViewById (R.id.text); textView.setOnClickListener (new View.OnClickListener () { @Override public void onClick (final View v) { } }); } 

Una opción es reenviar la posición presionada y la posición del hotspot a través de la vista principal.

 // Since the host view actually supports clicks, you can return false // from your touch listener and continue to receive events. myTextView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent e) { // Convert to card view coordinates. Assumes the host view is // a direct child and the card view is not scrollable. float x = e.getX() + v.getLeft(); float y = e.getY() + v.getTop(); // Simulate motion on the card view. myCardView.drawableHotspotChanged(x, y); // Simulate pressed state on the card view. switch (e.getActionMasked()) { case MotionEvent.ACTION_DOWN: myCardView.setPressed(true); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: myCardView.setPressed(false); break; } // Pass all events through to the host view. return false; } }); 
  • Uso del rango de búsqueda personalizado en android
  • ProgressBar mientras carga ListView (con AsyncTask)
  • Editado
  • Cómo obtener propiedades AttributeSet
  • ¿Por qué la vista previa de Mi cámara muestra Horizontal en lugar de Vertical?
  • Android: Creación de preferencias personalizadas
  • El elemento ITEM no está permitido en MENU
  • AutoCompleteTextView setError
  • Detectar si TextView abarca más de 2 líneas
  • Alinee los valores del hilador a la derecha en lugar de a la izquierda
  • ¿Por qué el margen no funciona?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.