2013-08-30 51 views
0

我爲我的應用程序的操作欄創建了自定義佈局。除了不確定的進度一切都工作正常,我通過requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);啓用onCreate()顯示了我的自定義佈局的右側,每當它出現在移動的一切:如何在自定義操作欄佈局中設置不確定進度?

enter image description here

這裏是我的自定義操作欄佈局:

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

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:text="@string/app_name" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true"/> 

    <SearchView 
     android:id="@+id/search_view" 
     android:layout_height="match_parent" 
     android:layout_width="wrap_content" 
     android:title="@string/menu_search" 
     android:icon="@drawable/ic_search" 
     android:showAsAction="always" 
     android:actionViewClass="android.widget.SearchView" 
     android:layout_alignParentLeft="false" 
     android:queryHint="@string/menu_search_hint" 
     android:iconifiedByDefault="false" 
     android:layout_alignParentRight="true" 
     /> 

    <ProgressBar 
     android:id="@+id/progress_spinner" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     style="?android:attr/progressBarStyleSmall" 
     android:layout_centerVertical="true" 
     android:indeterminate="true" 
     android:layout_toStartOf="@id/search_view" /> 

</RelativeLayout> 

我可以在我的自定義操作欄佈局中對ProgressBar做什麼,以便requestWindowFeature()找到並使用它而不是默認的?

回答

0

所以我想出了一個解決方案。除了使用requestWindowFeature()的,我引用我會放在動作條的佈局進度,取而代之的setProgressBarIndeterminateVisibility()所有實例setVisibility()

// Toggles progress spinner visibility when we conduct a search 
private void toggleIndeterminateSpinner(int state) 
{ 
    // Indeterminate Progress Spinner 
    ProgressBar progressSpinner = (ProgressBar) getActivity().findViewById(R.id.progress_spinner); 

    switch(state) 
    { 
    case HIDE: 
     progressSpinner.setVisibility(View.VISIBLE); 
     break; 
    case SHOW: 
     progressSpinner.setVisibility(View.GONE); 
     break; 
    } 
} 
相關問題