Reputation: 566
I have set button property clickable="false"
which inside a card, which has a property clickable=true
and android:foreground="?android:attr/selectableItemBackground"
, but when I click on card the button is also showing ripple effect. Here is my code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_marginTop="8dp">
<android.support.v7.widget.CardView
android:id="@+id/payment_card_view"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp"
card_view:cardBackgroundColor="#fff"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="4dp">
<Button
android:id="@+id/monthlySubscriptionPayButton"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:text="@string/payment_pay_text"
android:textAllCaps="true"
android:textColor="@color/junkart_color"
android:textSize="14sp"
android:clickable="false"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Thanks!
Upvotes: 2
Views: 1307
Reputation: 16910
A solution might be setting the button to disabled (setEnabled(false)
) next to being not clickable. Although this might not be an option if the style is different for disabled buttons.
Upvotes: 2
Reputation: 56
Set clickable attribute false on CardView. If parent view is clickable drawable state change event will dispatch to child view, no matter child view is clickable or not.
Upvotes: 0
Reputation: 4453
Set clickable="true"
and foreground="?android:attr/selectableItemBackground"
value in LinearLayout inside CardView and your problem will be solved.
Refer below changes I've made in your code:
<android.support.v7.widget.CardView
android:id="@+id/payment_card_view"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp"
card_view:cardBackgroundColor="#fff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="4dp">
<Button
android:id="@+id/monthlySubscriptionPayButton"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:text="@string/payment_pay_text"
android:textAllCaps="true"
android:textColor="@color/junkart_color"
android:textSize="14sp"
android:clickable="false"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
Hope it helps to you. Let me know if it is solved.
Upvotes: 1