2014-07-21 57 views
3

我有一個進度條,我將其背景設置爲透明。它適用於較新版本的Android,但在14和15上顯示爲黑色。這是我的佈局:在api上顯示爲黑色的透明背景14-15

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".RaceActivity" > 
<ProgressBar 
    android:id="@+id/speedometer_view" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@id/speedometer_title" 
    android:layout_below="@id/current_distance_title" 
    android:padding="8dp" 
    android:background="@android:color/transparent" 
    android:progressDrawable="@drawable/speedometer_progress_bar" 
    style="@android:style/Widget.ProgressBar.Horizontal"/>  

</RelativeLayout> 

我的應用程序的主題是android:Theme.Holo.Light.DarkActionBar。

任何想法如何使它透明?

+0

這可能是應用程序的主題是黑色的,所以雖然你有進度條上的透明度,容器元素有一個黑色的背景。 – stevebot

+0

謝謝你的幫助stevebot我回答了答案。 – yaronbic

回答

1

它可能與您正在使用的主題有關。確保您明確設置了進度條下面的視圖的顏色。

Holo Light和Holo Dark爲根元素設置了不同的默認背景,因此覆蓋它們可能會解決您的問題。

​​

+5

雖然我不確定它是答案但很可能,但我將此答案標記爲正確。我最終編輯@ drawable/speedometer_progress_bar這是一個圖層列表,最後一項是@android:id/background。由於某些原因,它在android 17或更高版本中透明,但16或更低的黑色可能與主題相關。我在該項目中添加了一個,這個技巧。感謝您的幫助 – yaronbic