我正在使用自定義標題視圖,並希望在線程工作時在標題視圖中顯示/隱藏進度條。Android - 使用runOnUiThread從線程執行UI更改
這是我的標題視圖的XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/image_left_btn"
android:layout_width="75dip"
android:layout_height="wrap_content"
android:text="Back"
/>
<TextView
android:id="@+id/image_title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="20dip"
android:textStyle="bold"
android:textColor="#fff"
android:layout_gravity="center"
android:gravity="center"
android:paddingLeft="8dip"
android:paddingRight="8dip"
/>
<ProgressBar
android:id="@+android:id/progress_small_title"
style="?android:attr/progressBarStyleSmall"
android:layout_width="75dip"
android:layout_height="wrap_content"
android:paddingRight="8dip"/>
</LinearLayout>
在我的活動,設置此爲自定義標題欄後,我做這個
titleProgress = (ProgressBar)findViewById(R.id.progress_small_title);
titleProgress.setVisibility(View.INVISIBLE);
其中titleProgress是進度的對象。
這是我在我的線程
runOnUiThread(new Runnable() {
public void run() {
titleProgress.setVisibility(View.VISIBLE);
}
});
//long operation here
runOnUiThread(new Runnable() {
public void run() {
titleProgress.setVisibility(View.INVISIBLE);
}
});
做但有進度條沒有變化。它從不顯示。有人可以告訴我什麼是錯誤的代碼?
是否可以在自定義標題中顯示標題進度條?
謝謝。
已經嘗試了前兩個,但沒有幫助!而絕望,我是這樣想的,要求3? ;) – lostInTransit 2009-09-23 08:01:21
3)選項是解決所有問題的最佳解決方案...... LOL – Rodrigo 2016-04-22 20:41:05