I am not able to use ripple effect on pressing on a tab please help I have tried a lot and struggling with it whole day.How can I use ripple effect on both pre-lollipop and lollipop devices any suggestion?
MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPager=(ViewPager)findViewById(R.id.pager);
mPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager(),getApplicationContext()));
mTabs=(SlidingTabLayout)findViewById(R.id.tabs);
mTabs.setDistributeEvenly(true);
mTabs.setCustomTabView(R.layout.customtablayout,R.id.textTab);
mTabs.setBackgroundColor(getResources().getColor(R.color.colorAccent));
mTabs.setSelectedIndicatorColors(getResources().getColor(R.color.colorPrimary));
mTabs.setViewPager(mPager);
}
activitymain.xml
<sarveshchavan777.inrerface2.SlidingTabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
customtablayout.xml
<ImageView
android:id="@+id/imageTab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<TextView
android:id="@+id/textTab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom|center" />
use this code for any item you want to give it ripple effect.
copy this code into a new XML file in the drawable folder. and set it as the background of any item you want ripple effect for.