android進度條的樣式

來源:互聯網
上載者:User

android 進度條的樣式


 
例1:(預設樣式(中等圓形))
Xml代碼 
<ProgressBar  
    android:id="@+id/progressBar1" 
    android:layout_width="wrap_content"  
    android:layout_height="wrap_content"  
    /> 
例2:(超大圓形)
Xml代碼 
<ProgressBar  
    android:id="@+id/progressBar2" 
    android:layout_width="wrap_content"  
    android:layout_height="wrap_content"  
    style="?android:attr/progressBarStyleLarge" 
    /> 
例3:(小號圓形)
Xml代碼 
<ProgressBar  
    android:id="@+id/progressBar3" 
    android:layout_width="wrap_content"  
    android:layout_height="wrap_content"  
    style="?android:attr/progressBarStyleSmall" 
    /> 
例4:(標題小號圓形) 
Xml代碼 
<ProgressBar  
    android:id="@+id/progressBar4" 
    android:layout_width="wrap_content"  
    android:layout_height="wrap_content"  
    style="?android:attr/progressBarStyleSmallTitle" 
    /> 
 
例4-在標題中使用小號圓形的使用代碼:


 
Java代碼 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    //設定標題不確定性進度條風格 
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); 
    setContentView(R.layout.progress_bars); 
    //顯示標題不確定性進度條 
    setProgressBarIndeterminateVisibility(true); 
    //關閉標題不確定性進度條 
    //setProgressBarIndeterminateVisibility(false); 

 
例5:(長方形進度條) 
Xml代碼 
<ProgressBar  
    android:id="@+id/progressBar5" 
    android:layout_width="200dp"  
    android:layout_height="wrap_content"  
    style="?android:attr/progressBarStyleHorizontal" 
    android:max="100" 
    android:progress="50" 
    android:secondaryProgress="70" 
    /> 
 
            android:max="100" 最大進度值100
            android:progress="50" 當前初始化進度值50
            android:secondaryProgress="70" 當前初始化第2進度值70
 
 
例5-在標題中使用長方形進度條的代碼:


Java代碼 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
     
    //設定標題進度條風格 
    requestWindowFeature(Window.FEATURE_PROGRESS); 
    setContentView(R.layout.progress_bars); 
    //顯示標題進度 
    setProgressBarVisibility(true); 
    //設定標題當前進度值為5000(標題進度最大值預設為10000) 
    setProgress(5000); 
    //關閉標題進度 
    //setProgressBarVisibility(false); 

 
例6:(進度對話方塊-圓形進度條)


Java代碼 
ProgressDialog dialog = new ProgressDialog(this); 
//設定進度條風格,風格為圓形,旋轉的 
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 
//設定ProgressDialog 標題 
dialog.setTitle("進度對話方塊"); 
//設定ProgressDialog 提示資訊 
dialog.setMessage("圓形進度條"); 
//設定ProgressDialog 標題表徵圖 
dialog.setIcon(android.R.drawable.ic_dialog_map); 
//設定ProgressDialog 的一個Button 
dialog.setButton("確定", new ProgressDialog.OnClickListener(){ 
    @Override 
    public void onClick(DialogInterface dialog, int which) { 
         
    } 
}); 
//設定ProgressDialog 的進度條是否不明確 
dialog.setIndeterminate(false); 
//設定ProgressDialog 是否可以按退回按鍵取消 
dialog.setCancelable(true); 
//顯示 
dialog.show(); 
 
例7:(進度對話方塊-長方形進度條)


Java代碼 
ProgressDialog dialog = new ProgressDialog(this); 
//設定進度條風格,風格為圓形,旋轉的 
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 
//設定ProgressDialog 標題 
dialog.setTitle("進度對話方塊"); 
//設定ProgressDialog 提示資訊 
dialog.setMessage("長方形進度條"); 
//設定ProgressDialog 標題表徵圖 
dialog.setIcon(android.R.drawable.ic_dialog_alert); 
//設定ProgressDialog的最大進度 
dialog.setMax(100); 
//設定ProgressDialog 的一個Button 
dialog.setButton("確定", new ProgressDialog.OnClickListener(){ 
    @Override 
    public void onClick(DialogInterface dialog, int which) { 
         
    } 
}); 
//設定ProgressDialog 是否可以按退回按鍵取消 
dialog.setCancelable(true); 
//顯示 
dialog.show(); 
 
//設定ProgressDialog的當前進度 
dialog.setProgress(50);

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.