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"
- Tomas de cajones niños vistas superpuestas
- gridview de las imágenes no se está actualizando
- ¿Cómo resalto el texto buscado en mi filtro de búsqueda?
- Mapas de Android: uso de un diseño como elemento de superposición
- ExpandableListView / Drill-Down en el menú deslizante
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) { } }); }
- El fragmento dentro de VideoView hace que la pantalla negra se deslice
- ¿Cómo igualmente span botones / diseños verticalmente en android?
- Creación de un fragmento en una ventana emergente - en Android
- XML selector de fondo no funciona en 2.3
- Estilo personalizado listdivider
- Cómo saber cuál es el soporte de teléfono que diseño (hdpi, mdpi y xhpi)?
- Android Studio: xmlns: el mapa no funciona
- Añadir diseño con parámetros programáticamente Android
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; } });
- Cómo configurar un observador para actualizar el cajón de navegación después de que el método onActivityResult recibió un resultado de intención
- Android – ViewPager Adapter, establece el elemento principal antes de que el adaptador se instancia