1. 程式人生 > >Android進度條樣式

Android進度條樣式

源地址:http://blog.csdn.net/tianyitianyi1/article/details/7563027?locationNum=2&fps=1

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);