I have a TextView inside a CardView. When enabling the ripple effect for Lollipop on the CardView by adding a OnClick event and adding the property:
android:foreground="?android:attr/selectableItemBackground"
It works fine. But after adding a OnClick event to the TextView, the ripple effect still shows up when I click outside of the TextView, but it won't show when clicking on the TextView area.
Is there away to show the ripple even when I click the TextView?
Here is 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>
Here is the code:
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) {
}
});
}