使用下方的小三角形设置选定的 TAB [英] Setting selected TAB with a small triangle below it
问题描述
我希望我的标签显示在图像中,下方带有小三角形.这可能吗?如果是,请帮助我提供一些代码或文档.
I want my tabs to show like in the image with small triangle below it.Is this possible ?If yes, then help me with some codes or documentation.
推荐答案
我认为,下面的方法是最简单的.您只需要设置以下可绘制对象(实际上,它是 Android 对选项卡的默认可绘制对象)作为选项卡的背景:
I think, the following approach is the simplest one. You just need to setup the following drawable (actually, it's Android's default drawable for tabs) as a background of the tabs:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected" />
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_focus" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_focus" />
<!-- Pressed -->
<item android:state_pressed="true" android:drawable="@drawable/tab_press" />
</selector>
其中 tab_press
、tab_focus
和 tab_selected
可绘制对象将是 png(我更喜欢 9-patches) 附近有向下箭头和透明区域.tab_unselected
drawable 不会有这个箭头,但仍然会有相同的透明区域.剩下要做的唯一一件事就是为您的 TabWidget
指定负底边距.它的值由箭头的高度决定(不要忘记使用 密度无关单位):
where tab_press
, tab_focus
and tab_selected
drawables would be png's (I'd prefer 9-patches) with down-arrow and transparent region near it. tab_unselected
drawable wouldn't have this arrow, but still would have same transparent region. The only thing left to do is to specify negative bottom margin for your TabWidget
. Its value is determined by the height of the arrow (do not forget to use density independent units):
这篇关于使用下方的小三角形设置选定的 TAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!