【问题标题】:Using ProgressDialog in ActionBar (Android)在 ActionBar 中使用 ProgressDialog (Android)
【发布时间】:2012-09-30 15:37:13
【问题描述】:

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

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

进行中.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>

在 menu.xml 中

<item
    android:id="@+id/Refresh"
    android:icon="@drawable/ic_menu_refresh"
    android:showAsAction="always"
    android:title="Refresh"/>

在我的活动中

    case R.id.Refresh:
        item.setActionView(R.layout.progress);
        return true;

这是我当前的 PD(在活动中)在我的 AsyncTask 的 onPreExecuteonPostExecute

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


// Post    
dialog.dismiss(---.this);

那么我该如何移动它,以便在onPreExecute 中激活操作栏指示器,然后在onPostExecute 中停止?

编辑:我不仅在寻找刷新,而且在您首次加载活动(或执行需要 PD 激活的操作)时寻找“加载”指示器。默认情况下应该是隐藏的。

【问题讨论】:

  • 编辑后,标题不再匹配问题,我想。

标签: android android-actionbar progressdialog


【解决方案1】:

我想我将不得不回答我自己的问题。这其实很简单。

在活动中,就在setContentView上方

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

AsyncTask

// pre
setProgressBarIndeterminateVisibility(true);

// Get Data

// post
setProgressBarIndeterminateVisibility(false);

【讨论】:

    【解决方案2】:

    如果您必须在 onCreate()

    中要求
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);  
    setProgressBarIndeterminateVisibility(true); 
    

    或者如果您使用的是支持包,它会是

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);  
    setSupportProgressBarIndeterminateVisibility(true); 
    

    如果您发现任何问题,请发表评论。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-30
      • 1970-01-01
      • 1970-01-01
      • 2016-07-29
      • 2012-12-04
      • 2011-08-21
      • 1970-01-01
      相关资源
      最近更新 更多