When I use RippleDrawable with API 10 using DesignSupportLibrary I got android.view.InflateException error in the layout of the list item
minSDK = 10 using DesignSupportLibrary .
Im using RecycleView and in adapter, when im inflating layout view in onCreateViewHolder () method and im using RippleDrawable in this layout XML file, i got this error,
LogCat
E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.LinearLayout
at android.view.LayoutInflater.createView(LayoutInflater.java:518)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at com.demo_toolbarall.RespondScrollEvent$Myadapter.onCreateViewHolder(RespondScrollEvent.java:83)
at com.demo_toolbarall.RespondScrollEvent$Myadapter.onCreateViewHolder(RespondScrollEvent.java:70)
But when I remove the RippleDrawable from the viewItem viewml it works, so I cannot use the Ripple effect.
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripples"
android:gravity="center_vertical"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/avatar"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginRight="16dp"/>
<TextView
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?attr/textAppearanceListItem"/>
</LinearLayout>
MyAdapter.class
class Myadapter extends RecyclerView.Adapter<Myadapter.ViewHolder> {
Context mContext;
List<String> mList;
View view;
public Myadapter(Context mContext, List<String> mList) {
this.mContext = mContext;
this.mList = mList;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
view = LayoutInflater.from(RespondScrollEvent.this).inflate(R.layout.list_item, parent, false);
return new ViewHolder(view);
}
ripples.xml
<?xml version="1.0" encoding="utf-8"?>
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/window_background2">
<item>
<shape>
<solid android:color="#FFFFFF" />
</shape>
</item>
</ripple>
If anyone gives an answer, that would be great and my honor too.
RippleDrawable was added in API Level 21 and unfortunately not yet part of the support library. It will most likely appear in a future update, but no timing has been announced yet.
Fortunately, there are several custom implementations already available:
https://github.com/traex/RippleEffect
https://github.com/balysv/material-ripple
https://github.com/siriscac/RippleView
https://github.com/ozodrukh/RippleDrawable
including the Materlial themed widget set, compatible with older Android versions:
https://github.com/keithellis/MaterialWidget
so you can try one of these or google for other "content widgets".