Remove highlight on press in tablayout
Asked Answered
C

2

9

enter image description here

How to disable this highlight on pressing the tab. I have been searching for half an hour and couldn't figure it out. I am using tablayout.

Continuo answered 16/6, 2016 at 17:57 Comment(0)
V
11

just set the background color to transparent or to the background color of the tablayout. Add the following code to the parent layout.

 xmlns:app="http://schemas.android.com/apk/res-auto"

And add the following to tablayout.

app:tabBackground="?attr/colorPrimary"
android:background="?attr/colorPrimary"

This will solve your problem. Tested in Android M.

Vareck answered 16/6, 2016 at 18:19 Comment(3)
In my xml I have Toolbar and TabLayout and ViewPager. Toolbar and Tablayout have their backgrounds set but it still highlights on press. Maybe I am doing something wrong.Continuo
add the following code to parent layout xmlns:app="schemas.android.com/apk/res-auto" and the following code to the tablayout app:tabBackground="?attr/colorPrimary" android:background="?attr/colorPrimary" Tested with the android version M and it is working.Vareck
app:tabBackground saved the day. Thanks.Continuo
K
15

Add the below line to your XML:

app:tabRippleColor="@android:color/transparent"
Kial answered 26/5, 2019 at 7:23 Comment(3)
This should be added to the excepted answer. I was only able to remove all background highlights after also making the ripple transparent. Thanks!Aloise
If you want to disable color when unselected tab is selected,i.e: android:state_focused="true", then this is the solution. Thank you sir for this solution!Trainee
it's the wrong answer. The correct answer is not to hardcode this attributeBough
V
11

just set the background color to transparent or to the background color of the tablayout. Add the following code to the parent layout.

 xmlns:app="http://schemas.android.com/apk/res-auto"

And add the following to tablayout.

app:tabBackground="?attr/colorPrimary"
android:background="?attr/colorPrimary"

This will solve your problem. Tested in Android M.

Vareck answered 16/6, 2016 at 18:19 Comment(3)
In my xml I have Toolbar and TabLayout and ViewPager. Toolbar and Tablayout have their backgrounds set but it still highlights on press. Maybe I am doing something wrong.Continuo
add the following code to parent layout xmlns:app="schemas.android.com/apk/res-auto" and the following code to the tablayout app:tabBackground="?attr/colorPrimary" android:background="?attr/colorPrimary" Tested with the android version M and it is working.Vareck
app:tabBackground saved the day. Thanks.Continuo

© 2022 - 2024 — McMap. All rights reserved.