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>
I am using the DesignSupportLibrary (v22.2.0) and want the tabs in the TabLayout to be the same width - regardless the tab text length. I have tried MODE_FIXED but it still shows the tabs with different widths. Here is the xml:
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:tabMode="fixed"/>
If you want to specify the minimum width for each tab, you can set it in the style:
<style name="MyTabLayoutStyle" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="tabMinWidth">100dp</item>
</style>
and then set the theme to this style instead (you can delete the tabMode attribute as well):
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="#style/MyTabLayoutStyle"/>
Alternately, you can set the tabMinWidth directly on the TabLayout:
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:tabMinWidth="100dp"/>
An additional note: It looks like MODE_FIXED does not work properly unless you define the layout_width of the TabLayout (instead of using "wrap_content"). However the tabs will still only expand to match the widest tab (as determined by the longest length of text). So if your defined width is larger than the generated tabs. there will be an empty space to the right of the tabs.
<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.
I am using Material design library and creating layout using CoordinatorLayout ,AppBarLayout ,RecyclerView and TabLayout .
My issue is i am unable to see Tab indicator in Tablayout .Below is my xml file that i am using in AppCompactActivity.
<android.support.design.widget.CoordinatorLayout
android:id="#+id/coodinate_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/btn_next_screen">
<android.support.v7.widget.RecyclerView
android:id="#+id/list_recycle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="30dp"
android:background="#color/white"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
/>
<android.support.design.widget.AppBarLayout
android:id="#+id/abar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_home"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabBackground="#color/tab_bg"
app:tabIndicatorColor="#color/tab_indicator"
app:tabIndicatorHeight="5dp"
app:tabMode="fixed"
></android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
app:layout_anchor="#+id/list_recycle"
app:layout_anchorGravity="bottom|right"
android:id="#+id/floatin_ab_home"
app:fabSize="mini"
android:src="#drawable/ic_content_add"
/>
</android.support.design.widget.CoordinatorLayout>
Below is screen which don't showing Tab indicator so can any one known what i am missing .
I think it's bug on Design Support library. that
When You apply both property at the same time
app:tabBackground="#color/tab_bg"
app:tabIndicatorColor="#color/tab_indicator"
the background color overlap the tab indicator. that's why the tab indicator is not visible.
If you remove tabBackground color property then you can see the indicator.
[Update on 25-06-2015]
As I said it's bug on Design Support library. I reported it to android bug source. here is the refrence https://code.google.com/p/android/issues/detail?id=176540.
So status for this is issue is FutureRelease so bug is fixed. And it will come in future library.
[Update 20-07-2015]
The bug is fixed and Released in v 22.2.1. you can also check it on above link.
You can use below methods
1 Change in xml
app:tabIndicatorColor="" set your indicator color
2 creating costume theme
<style name="AppTheme.TabStyle" parent="Widget.Design.TabLayout">
<item name="tabTextAppearance">#style/AppTheme.TextStyle</item>
<item name="tabTextColor">#color/primaryDark</item>
<item name="tabSelectedTextColor">#color/white</item>
<item name="tabIndicatorColor">#color/primaryDark</item>
<item name="tabIndicatorHeight">3dp</item>
<item name="android:background">?attr/colorPrimary</item>
</style>
<style name="AppTheme.TextStyle" parent="TextAppearance.Design.Tab">
<item name="android:textSize">14sp</item>
<item name="textAllCaps">true</item>
</style>
set theme in your Tablayout
I've just fixed this bug set background color programmatically
tabLayout.setBackgroundColor(getResources().getColor(R.color.primary));
or in xml
android:background="#color/primary"
But I don't know if there is any problem when you set background color this way
Here you go.. :)
Change your attribute
app:tabBackground="#color/tab_bg"
to
android:background="#color/tab_bg"
your final code..
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/tab_bg"
app:tabIndicatorColor="#color/tab_indicator"
app:tabIndicatorHeight="5dp"
app:tabMode="fixed">
</android.support.design.widget.TabLayout>
You are using RecyclerView as the main content, use ViewPager containing RecyclerView and make sure you give viewpage attribute app:layout_behavior="#string/appbar_scrolling_view_behavior"
If anyone still facing the problem this is
Working example from my existing application, try using it and modify based on your needs.
<com.google.android.material.tabs.TabLayout
android:id="#+id/homeScreenTab"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#color/design_default_color_primary_dark"
app:tabIndicatorColor="#color/black"
app:tabGravity="fill"
app:tabIndicatorHeight="3dp"
app:tabMaxWidth="0dp"
app:tabMode="fixed"
app:tabSelectedTextColor="#android:color/white" />
I'm using the new android.support.v7.widget.ActionMenuView (v7, r21) to mimic a split action bar in my application. My top toolbar is themed with ThemeOverlay.AppCompat.Dark.ActionBar, so its text and overflow icon appear white. The ActionMenuView content however appears black, is there a way to apply the theme there as well or at least color the option items text white?
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:support="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="#+id/bar_action"
android:background="?attr/colorPrimary"
support:popupTheme="#style/ThemeOverlay.AppCompat.Light"
support:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<android.support.v7.widget.ActionMenuView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="#+id/bar_split"
android:background="?attr/colorPrimary" />
Stupid me, didn't define android:textColorPrimary in my theme!