2014-05-15 100 views
0

我想製作簡單的TabPagerIndicator,但它不顯示下劃線,我使用xml來改變樣式。這是我的XML樣式文件:ViewPagerIndicator不顯示下劃線標籤

<!-- Application theme. --> 
<style name="AppTheme" parent="@style/Theme.AppCompat.Light"> 
    <item name="vpiTitlePageIndicatorStyle">@style/CustomTitlePageIndicator</item> 
    <item name="vpiUnderlinePageIndicatorStyle">@style/CustomUnderlinePageIndicator</item> 
    <item name="vpiTabPageIndicatorStyle">@style/CustomTabPageIndicator</item> 
</style> 

<style name="CustomTabPageIndicator" parent="Widget.TabPageIndicator"> 
    <item name="android:background">@color/fondo_activity</item> 
    <item name="android:textAppearance">@style/CustomTabPageIndicator.Text</item> 
    <item name="android:textColor">#FF555555</item> 
    <item name="android:textSize">14sp</item> 
    <item name="android:dividerPadding">10dp</item> 
    <item name="showDividers">middle</item> 
    <item name="android:paddingLeft">8dp</item> 
    <item name="android:paddingRight">8dp</item> 
    <item name="android:fadingEdge">horizontal</item> 
    <item name="android:fadingEdgeLength">8dp</item> 
</style> 

<style name="CustomTabPageIndicator.Text" parent="android:TextAppearance.Medium"> 
    <item name="android:typeface">monospace</item> 
</style> 

<style name="CustomUnderlinePageIndicator"> 
    <item name="selectedColor">#FFCC0000</item> 
    <item name="android:background">#FFCCCCCC</item> 
    <item name="fadeLength">1000</item> 
    <item name="fadeDelay">1000</item> 
</style> 


<style name="CustomTitlePageIndicator"> 
    <item name="android:background">#18FF0000</item> 
    <item name="footerColor">#FFAA2222</item> 
    <item name="footerLineHeight">1dp</item> 
    <item name="footerIndicatorHeight">3dp</item> 
    <item name="footerIndicatorStyle">underline</item> 
    <item name="android:textColor">#AA000000</item> 
    <item name="selectedColor">#FF000000</item> 
    <item name="selectedBold">true</item> 
</style> 

在這張圖片中,你可以看到它是如何顯示(頂部的紅線是操作欄的一部分) enter image description here

有誰知道哪裏是錯誤和我如何解決它?

最好。

+0

這個下劃線是不能從xml..its代碼改成java文件的。 – dipali

+0

我該怎麼做呢? – aloj

+0

上:(:(誰能幫我嗎? – aloj

回答

0

您可以使用背景屬性設置下劃線。將其設置爲一個XML drawable,它定義使用哪個drawable/9-patches來繪製不同的狀態。

<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/vpi__tab_unselected_holo" /> 
    <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/vpi__tab_selected_holo" /> 

    <!-- Focused states --> 
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/vpi__tab_unselected_focused_holo" /> 
    <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/vpi__tab_selected_focused_holo" /> 

    <!-- Pressed --> 
    <!-- Non focused states --> 
    <item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/vpi__tab_unselected_pressed_holo" /> 
    <item android:state_focused="false" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/vpi__tab_selected_pressed_holo" /> 

    <!-- Focused states --> 
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/vpi__tab_unselected_pressed_holo" /> 
    <item android:state_focused="true" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/vpi__tab_selected_pressed_holo" /> 
</selector>