gpt4 book ai didi

Android TabLayout 选中的tab背景

转载 作者:太空宇宙 更新时间:2023-11-03 13:48:26 28 4
gpt4 key购买 nike

真的没有简单的方法来使用 TabLayout 并能够设置选项卡的颜色(选中,未选中)吗?就像选中的标签背景使用 colorPrimary,未选中的标签使用 colorPrimaryDark 之类的?我在网上搜索过 thisthis以及更多。我可以使用解决方案 1 更改背景颜色,但现在指示器丢失了,我想要它回来。

这不是很难做到..

missing indicator

第一个链接的解决方法:

<style name="Base.Widget.Design.TabLayout" parent="android:Widget">
<item name="tabBackground">@drawable/tab_background</item>
</style>

// tab_background
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/tab_background_selected" android:state_selected="true" />
<item android:drawable="@drawable/tab_background_unselected" android:state_selected="false" android:state_focused="false" android:state_pressed="false" />
</selector>

回答:

<style name="Base.Widget.Design.TabLayout" parent="android:Widget">
<item name="tabBackground">@drawable/tab_background</item>
<item name="tabIndicatorColor">@color/colorAccent</item>
<item name="tabIndicatorHeight">3dp</item>
</style>

最佳答案

风格改变

  <style name="Base.Widget.Design.TabLayout" parent="android:Widget">
<item name="tabBackground">@drawable/tab_background</item>
<item name="tabIndicatorColor">#000000</item>
<item name="tabIndicatorHeight">5dp</item>
</style>

关于Android TabLayout 选中的tab背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38202585/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com