2013-07-25 49 views
0

我正在使用操作欄sherlock。我有一個透明像素的圖標。但是當我運行我的應用程序時,似乎「某種東西」將主題背景替換爲這些透明像素,而不是操作欄背景。操作欄填充背景錯誤的透明圖標像素

如果主背景被指定爲@color或@drawable(9 patch),但在後一種情況下(這是我真正想要的),沒關係,還有一個額外的怪癖,那就是幾個像素點主背景9補丁出現在操作欄的右側(!)手邊。去搞清楚。

我不知道這裏發生了什麼。只是,如果我從主風格中刪除背景項目,操作欄看起來應該是這樣(所以這似乎是問題)。

有沒有其他人見過這樣的行爲?謝謝參觀!

我會粘貼下面我style.xml:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 

<declare-styleable name="ViewPagerIndicator"> 
    <attr name="vpiSubTabPageIndicatorStyle" format="reference"/> 
</declare-styleable> 

<style name="Theme.StandBy" parent="Theme.Sherlock.Light.DarkActionBar"> 

    <item name="vpiTabPageIndicatorStyle">@style/CustomTabPageIndicator</item> 
    <item name="vpiSubTabPageIndicatorStyle">@style/CustomSubTabPageIndicator</item> 
    <item name="android:actionBarStyle">@style/Theme.StandBy.App.ActionBar</item> 
    <item name="actionBarStyle">@style/Theme.StandBy.App.ActionBar</item> 

<!-- ------------------------------------------ -> 
<!-- I tried both of these, but can't get transparent pixels in my icon to work ---> 
<!-- when I use the 9 patch (frg_background) in stead of a plain color, there --> 
<!-- are extra artefacts in that some of the 9 patch pixels end up on the righthand --> 
<!-- side of the action bar --> 
    <!--<item name="android:background">@drawable/frg_background</item> 
    <item name="background">@drawable/frg_background</item>--> 
    <item name="android:background">@color/cream</item> 
    <item name="background">@color/cream</item> 
<!-- ------------------------------------------ -> 
</style> 

<style name="Theme.StandBySubTab" parent="Theme.Sherlock.Light.DarkActionBar"> 
    <item name="vpiTabPageIndicatorStyle">@style/CustomSubTabPageIndicator</item> 
</style> 

<style name="Theme.StandBy.App.ActionBar" parent="Widget.Sherlock.ActionBar"> 
    <!-- 
     Both `android:xyz` and `xyz` need to be set to support 4.x and 2.x devices. 
    --> 
    <item name="android:displayOptions">showHome</item> 
    <item name="displayOptions">showHome</item> 
    <item name="android:background">@drawable/bar</item> 
    <item name="background">@drawable/bar</item> 
</style> 

<!-- top tab style --> 
<style name="CustomTabPageIndicator" parent="Widget.TabPageIndicator"> 
    <item name="android:background">@drawable/tab_background</item> 
    <item name="android:textAppearance">@style/CustomTabPageIndicator.Text</item> 
    <item name="android:divider">@drawable/tab_divider</item> 
    <item name="android:showDividers">middle</item> 
    <item name="android:paddingLeft">4dp</item> 
    <item name="android:paddingRight">4dp</item> 
</style> 
<style name="CustomTabPageIndicator.Text"> 
    <item name="android:textColor">@color/tab_text</item> 
    <item name="android:textSize">10sp</item> 
    <item name="android:textStyle">bold</item> 
</style> 

<!-- sub tab style --> 
<style name="CustomSubTabPageIndicator" parent="Widget.TabPageIndicator"> 
    <item name="android:background">@drawable/sub_background</item> 
    <item name="android:textAppearance">@style/CustomSubTabPageIndicator.Text</item> 
    <item name="android:paddingLeft">4dp</item> 
    <item name="android:paddingRight">4dp</item> 
</style> 
<style name="CustomSubTabPageIndicator.Text"> 
    <item name="android:textColor">@color/sub_text</item> 
    <item name="android:textSize">10sp</item> 
    <item name="android:textStyle">bold</item> 
</style> 

</resources> 

編輯:既然問題消失,如果我沒有在我的主要風格指定backgroundandroid:background(Theme.StandBy),它發生在我,我可能會問錯誤的問題。我將這些項目放入的目的是爲我的所有片段(選項卡的內容)指定默認背景。這有效,但有我上面提到的不需要的副作用。我應該以另一種方式來做這件事嗎?感謝您的任何建議!

+0

我沒有答案,但只是fyi Google昨天發佈了ActionBarCompat,它是一個將Action欄降至api 7的庫。 - https://www.youtube.com/watch?v=6TGgYqfJnyc – Shmuel

+0

謝謝!這會讓sherlock,也可能是我的問題消失。我會盡快嘗試(儘管我沒有多少使用sherlock的投訴,我應該補充)。但感覺,我認爲我只是在做一些非常愚蠢的事情,這可能仍然不能用於ActionBarCompat ... –

+0

每個David的建議我已經刪除了sherlock而贊成谷歌自己的support-v7-appcompat。正如我擔心的那樣,問題仍然存在。 –

回答

0

當視圖解析其樣式時,您在主題上設置的屬性將由EVERY視圖繼承。在你的情況下,其他地方沒有顯式背景的每個視圖都會呈現@ color/cream背景。這必然會導致您遇到的各種視覺問題,以及造成大量不必要的透支。

一個更好的方法,以通用的造型應用到您的片段是簡單地創建一個樣式

<style name="Fragment"> 
    <item name="android:background">@color/cream</item> 
</style> 

,並且從每個片段,例如根視圖引用它

<LinearLayout style="@style/Fragment"> 
    ... 
</LinearLayout> 

這意味着一些額外的輸入作爲參考的風格需要進入每一個片段,但要避免這種情況沒有什麼好辦法 - 從概念上講只有視圖類可以有自己的默認樣式由設置主題(例如,您可以將textViewStyle屬性指向樣式定義,並且它將應用於所有TextView)。然而片段(或活動)不是視圖,所以這個機制不適用。