2014-01-10 45 views
0

我有一個照片庫,在ViewPager中顯示照片。在黑暗的背景下不顯示Android進度條

詳細布局有一個黑暗的背景,幷包含一個ProgressBar,當圖像完全下載時我會隱藏它。適用於我的Nexus Android 4.4。

在HTC Desire Android 2.2上,ProgressBar無法在黑暗背景下看到,但如果我將ProgressBar本身的背景設置爲白色,則可以看到它顯示並正確隱藏。它在其他背景爲白色的佈局中也顯示得很好。

如何讓ProgressBar在2.2的黑色背景下出現?

這是我的佈局;

photo_detail_pager.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
    <android.support.v4.view.ViewPager 
     android:id="@+id/pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     /> 
</LinearLayout> 

photo_detail.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="@android:color/background_dark"> 
    <ProgressBar 
     android:id="@+id/loader" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     /> 
    <ImageView 
     android:id="@+id/photo" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     /> 
</RelativeLayout> 

回答

1

你可以嘗試 style="@android:style/Widget.ProgressBar.Inverse"。雖然默認設置應該顯示在黑色背景上,而逆設置顯示爲淺色背景,但10級以下的api可能會以不同的方式處理它。此外,您的主題可能會影響配色方案。

0

好吧,好像它是一種與主題的衝突。

我有android:theme =「@ style/Theme.AppCompat.Light.DarkActionBar」爲應用程序。

我設置了主題爲我的照片庫活動安卓主題=「@風格/ Theme.AppCompat」

在該片段中,迫使進度向前:

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.photo_detail, container, false); 

    loader = (ProgressBar) rootView.findViewById(R.id.loader); 
    loader.bringToFront(); 

    // other stuff... 
} 

而且在該活動明確地設置ActionBar背景爲黑色以擺脫全息藍線:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.photo_detail_pager); 

    getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.abc_ab_solid_dark_holo)); 

    // other stuff... 
}