Android ProgressBar 樣式[大全]

來源:互聯網
上載者:User

普通圓形ProgressBar  該類型進度條也就是一個表示運轉的過程,例如傳送簡訊,串連網路等等,表示一個過程正在執行中。一般只要在XML布局中定義就可以了。 [html]  <progressBar Android:id="@+id/widget43"        android:layout_width="wrap_content"         android:layout_height="wrap_content"          android:layout_gravity="center_vertical">  </ProgressBar>    此時,沒有設定它的風格,那麼它就是圓形的,一直會旋轉的進度條。  超大號圓形ProgressBar此時,給設定一個style風格屬性後,該ProgressBar就有了一個風格,這裡大號ProgressBar的風格是: style="?android:attr/progressBarStyleLarge"完整XML定義是: [html]  <progressBar android:id="@+id/widget196"        android:layout_width="wrap_content"         android:layout_height="wrap_content"        style="?android:attr/progressBarStyleLarge">  </ProgressBar>     小號圓形ProgressBar小號ProgressBar對應的風格是: style="?android:attr/progressBarStyleSmall"完整XML定義是: [html <progressBar android:id="@+id/widget108"        android:layout_width="wrap_content"         android:layout_height="wrap_content"        style="?android:attr/progressBarStyleSmall">  </ProgressBar>     標題型圓形ProgressBar標題型ProgressBar對應的風格是: style="?android:attr/progressBarStyleSmallTitle"完整XML定義是: [html] <progressBar android:id="@+id/widget110"      android:layout_width="wrap_content"       android:layout_height="wrap_content"      style="?android:attr/progressBarStyleSmallTitle">  </ProgressBar>    代碼中實現:    [java] @Override      protected void onCreate(Bundle savedInstanceState) {          // TODO Auto-generated method stub          super.onCreate(savedInstanceState);          requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);          //請求視窗特色風格,這裡設定成不明確的進度風格          setContentView(R.layout.second);          setProgressBarIndeterminateVisibility(true);          //設定標題列中的不明確的進度條是否可以顯示      }     長形進度條 布局中的長形進度條 ①首先在XML進行布局 [html]  <progressBar android:id="@+id/progressbar_updown"          android:layout_width="200dp"           android:layout_height="wrap_content"          style="?android:attr/progressBarStyleHorizontal"          android:layout_gravity="center_vertical"           android:max="100"          android:progress="50"          android:secondaryProgress="70" >     講解:style="?android:attr/progressBarStyleHorizontal"   設定風格為長形 android:max="100"   最大進度值為100 android:progress="50"  初始化的進度值 android:secondaryProgress="70" 初始化的底層第二個進度值 android:layout_gravity="center_vertical"   垂直置中   ②代碼中運用 private ProgressBar myProgressBar;[java]  //定義ProgressBar  myProgressBar = (ProgressBar) findViewById(R.id.progressbar_updown);  //ProgressBar通過ID來從XML中擷取  myProgressBar.incrementProgressBy(5);  //ProgressBar進度值增加5  myProgressBar.incrementProgressBy(-5);  //ProgressBar進度值減少5  myProgressBar.incrementSecondaryProgressBy(5);  //ProgressBar背後的第二個進度條 進度值增加5  myProgressBar.incrementSecondaryProgressBy(-5);  //ProgressBar背後的第二個進度條 進度值減少5     頁面標題中的長形進度條 代碼實現: ①先設定一下視窗風格特性 requestWindowFeature(Window.FEATURE_PROGRESS);[java] //請求一個視窗進度條特性風格  setContentView(R.layout.main);  setProgressBarVisibility(true);  //設定進度條可視      ②然後設定進度值 setProgress(myProgressBar.getProgress() * 100);[java]  //設定標題列中前景的一個進度條進度值  setSecondaryProgress(myProgressBar.getSecondaryProgress() * 100);  //設定標題列中後面的一個進度條進度值  //ProgressBar.getSecondaryProgress() 是用來擷取其他進度條的進度值    ProgressDialogProgressDialog中的圓形進度條ProgressDialog一般用來表示一個系統任務或是開啟任務時候的進度,有一種稍等的意思。代碼實現:  [java] ProgressDialog mypDialog=new ProgressDialog(this);    //執行個體化    mypDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);    //設定進度條風格,風格為圓形,旋轉的    mypDialog.setTitle("Google");    //設定ProgressDialog 標題    mypDialog.setMessage(getResources().getString(R.string.second));    //設定ProgressDialog 提示資訊    mypDialog.setIcon(R.drawable.android);    //設定ProgressDialog 標題表徵圖    mypDialog.setButton("Google",this);    //設定ProgressDialog 的一個Button    mypDialog.setIndeterminate(false);    //設定ProgressDialog 的進度條是否不明確    mypDialog.setCancelable(true);    //設定ProgressDialog 是否可以按退回按鍵取消    mypDialog.show();    //讓ProgressDialog顯示    ProgressDialog中的長形進度條 代碼實現:[java]  ProgressDialog mypDialog=new ProgressDialog(this);      //執行個體化     mypDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);    //設定進度條風格,風格為長形,有刻度的    mypDialog.setTitle("地獄怒獸");    //設定ProgressDialog 標題    mypDialog.setMessage(getResources().getString(R.string.second));    //設定ProgressDialog 提示資訊    mypDialog.setIcon(R.drawable.android);    //設定ProgressDialog 標題表徵圖    mypDialog.setProgress(59);    //設定ProgressDialog 進度條進度    mypDialog.setButton("地獄曙光",this);    //設定ProgressDialog 的一個Button    mypDialog.setIndeterminate(false);    //設定ProgressDialog 的進度條是否不明確    mypDialog.setCancelable(true);    //設定ProgressDialog 是否可以按退回按鍵取消    mypDialog.show();    //讓ProgressDialog顯示      

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.