在ActionBar中使用ProgressDialog(Android)

The*_*ter 9 android progressdialog android-actionbar

我正在尝试将ProgressDialog移动到我的ActionBar.

我知道如何将它放在动作栏中并为其设置动画(我认为),如下所示:

在progress.xml中

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="1" >

    <ProgressBar
        android:id="@+id/progress"
        style="?android:attr/progressBarStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </ProgressBar>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

在menu.xml中

<item
    android:id="@+id/Refresh"
    android:icon="@drawable/ic_menu_refresh"
    android:showAsAction="always"
    android:title="Refresh"/>
Run Code Online (Sandbox Code Playgroud)

在我的活动中

    case R.id.Refresh:
        item.setActionView(R.layout.progress);
        return true;
Run Code Online (Sandbox Code Playgroud)

这里是我目前的PD(在活动)onPreExecuteonPostExecute我的AsyncTask的:

// Pre  
dialog = new MyProgressDialog(---.this);
dialog.show(---.this);


// Post    
dialog.dismiss(---.this);
Run Code Online (Sandbox Code Playgroud)

那么如何移动它以便激活操作栏指示器onPreExecute然后停止onPostExecute

编辑:当你第一次加载一个活动(或做一些需要PD激活的东西)时,我不仅要寻找刷新,而且还要寻找"加载"指示器.它应该默认隐藏.

The*_*ter 7

我猜我将不得不回答我自己的问题.实际上这非常简单.

在活动中,就在上面 setContentView

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
Run Code Online (Sandbox Code Playgroud)

AsyncTask

// pre
setProgressBarIndeterminateVisibility(true);

// Get Data

// post
setProgressBarIndeterminateVisibility(false);
Run Code Online (Sandbox Code Playgroud)