Is there any way to wrap tab indicator width with respect to tab title ?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
As of support library 28 you can do the following:
You can set the desired padding that affects the tab indicator.
Also you can now do this:
this will set a custom drawable as indicator.
example of custom drawable:
Short answer is "no". Here is explanation.
There is private class
SlidingTabStrip
within TabLayout that draws indicatorI believe mIndicatorLeft and mIndicatorRight is what you need. These fields are set in the same class:
where left and right parameters are calculated in next method:
And the worst thing is that SlidingTabStrip field in TabLayout is private and final.
I don't see how it's possible to achieve what you need without creating totally new TabLayout.
You can do it using styles.
In the layout xml:
in the styles.xml:
I'm note sure about the SDK Version needed, but you can do it directly in your XML file, adding the padding attribute using app namespace.
Just make your TabLayout looks like this:
You can move the
xmlns:app="http://schemas.android.com/apk/res-auto"
for your parent layou too, but its your choice :)Thanks leon for his answer, that lead me to achieve that by XML.
I tried 2 hours for various solutions but none of those have a perfect effect.
The problem lies on the tabView's padding - even if I set its padding to all 0,
Different tabs still have different padding and therefore the text inside its
TextView
varies in size.Then I found this library which perfectly solved it.
https://github.com/H07000223/FlycoTabLayout
As @Stas Melnychenko said, we probably can't do it unless we re-write a
TabLayout
. And this library does re-write aTabLayout
...One simple solution is:
But it works with latest dependency like