The grey color appears for fraction of seconds when I touch on TabLayout. how to disable it?
The gray color you see after clicking the TabLayout is a ripple color. You can disable that by setting app:tabRippleColor="#null" in your XML.
Here is the code
<com.google.android.material.tabs.TabLayout
android:id="#+id/tabLayout"
app:tabRippleColor="#null"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.google.android.material.tabs.TabLayout>
Related
I'm using Tablayout + ViewPager as the UI frame.
There is a underline of the selected tab in tablayout.the length of text and the underline length don't equal.I wanna them equal
How to do this?
Thanks very much
I have the same requirement. You can use
app:tabIndicatorFullWidth="false"
I hope this will work for you.
You can change tabIndicator color and height like below
<android.support.design.widget.TabLayout
android:id="#id/pages_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="#android:color/white"
app:tabIndicatorHeight="4dp"/>
AFAIK you the tab indicator length is set to its tab width, you can't change only indicator size
if you really want to change try changing tabWidth so indicator also vary with this change.
app:tabMaxWidth="30dp"
app:tabMinWidth="210dp"
app:tabMaxWidth="110dp"
Add just these two line of code in your XML. Its depend on your tab item. You can modified just increase and decrease both at a time.
You can add another layout over tab layout and give padding accordingly.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:layout_below="#+id/toolbar"
android:id="#+id/tabLayout"
android:background="#color/colorTangerine">
<com.techlabs.oodhaar.views.CustomTabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabBackground="#color/colorTangerine"
app:tabIndicatorColor="#color/colorBackground"
app:tabSelectedTextColor="#color/colorBackground"
app:tabTextColor="#color/colorBackground"
app:tabIndicatorHeight="4dp"
/>
</RelativeLayout>
android TabLayout how to show shadow top
im using tablayout is bottom how to make shadow as like this
please help me ? shadow show top
<RelativeLayout
android:id="#+id/main_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".GlobalHub.GlobalActivity">
<android.support.v4.view.ViewPager
android:id="#id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/tablayout" />
<android.support.design.widget.TabLayout
singleLine="true"
android:id="#id/tablayout"
app:tabTextColor="#color/black"
app:tabMode="fixed"
app:tabGravity="fill"
app:tabIndicatorColor="#color/jetColor"
app:tabTextAppearance="#style/MyCustomTabLayout"
app:tabIndicatorHeight="6dp"
android:layout_width="match_parent"
android:layout_height="#dimen/_46sdp"
android:layout_alignParentBottom="true"
android:background="#drawable/shadow_tablayout"
/>
To get the shadow, use android:elevation attribute on the TabLayout in your xml file :
android:elevation="10dp"
read more about using elevation and defining shadows in Android here
If you just want the top shadow then try these 2 solutions :
OR
Wrap the Tablayout in a LinearLayout and set the background of LinearLayout as the 9patch image with top shadow.
OR
Put an ImageView above your TabLayout and set its src to be a vertical GradientDrawable defined in XML, as explained here
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
xmlns:android="http://schemas.android.com/apk/res`enter code here`/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:theme="#style/ThemeOverlay.AppCompat.ActionBar">
When i try to set toolbar alpha value as 0 at runtime it also hides the toolbar icons.
i need to set the toolbar background color as red at runtime with dynamic alpha.
please help me to fix this.
When I setup the tabBackground attribute of the "22.2.0 Android design library" TabLayout (android.support.design.widget.TabLayout) two problems appear :
The ripple effect in the tabs is lost
The tab indicator disappears.
This occurs on both Lollipop and Kitkat devices.
Without the tabBackground settings, both ripple effect and tab indicator work but the background has a default color that is different from the toobar, which is not exactly conform to the material design guidelines.
Please find below the XML :
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"
app:tabBackground = "?attr/colorPrimary" />
Use android:background="?attr/colorPrimary" instead of app:tabBackground = "?attr/colorPrimary".
If you have a dark primary color, you may also want to change the theme to ThemeOverlay.AppCompat.Dark. This makes the text and the ripple color white.
Full example:
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark" />
Here is my layout inside ViewPager. I would like to change the color of the current tab highlighter which is below the text. Actually it is showing in black color. But I don't know whether it is a color by default or not. And also I have one more doubt. If I use PagerTitleStrip this tab highlighter doesn't appear. Is there a way to bring that with titlestrip?
Here is my layout:
<android.support.v4.view.PagerTabStrip android:id="#+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#color/pager_titlestrip_bg"
android:textColor="#color/pager_titlestrip_text"
android:paddingTop="5dp"
android:paddingBottom="4dp" >
</android.support.v4.view.PagerTabStrip>
This just works.
PagerTabStrip pagerTabStrip = (PagerTabStrip) findViewById(R.id.pager_title_strip);
pagerTabStrip.setDrawFullUnderline(true);
pagerTabStrip.setTabIndicatorColor(Color.RED);
Thanks!
It can be done in both programmatically with jAVA or with XML
By XML
<android.support.design.widget.TabLayout
android:id="#+id/tabanim_tabs"
android:layout_width="match_parent"
app:tabIndicatorHeight="4dp"
app:tabIndicatorColor="#android:color/white"
android:layout_height="wrap_content" />
Or more simply you can solve this Code aswell
tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#FFFFFF"));
Similarly to change the Height
tabLayout.setSelectedTabIndicatorHeight((int) (2 * getResources().getDisplayMetrics().density));
This works in my project.
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFF"
app:tabGravity="fill"
app:tabIndicatorColor="#color/text3"
app:tabMode="scrollable"
app:tabSelectedTextColor="#color/text3"
app:tabTextColor="#000" />