android 進度條的樣式

android 進度條的樣式 html


 
例1:(默認樣式(中等圓形))
Xml代碼  java


<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代碼  android


<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-在標題中使用小號圓形的使用代碼: ide


 
Java代碼  this

@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-在標題中使用長方形進度條的代碼: spa


Java代碼  code

@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:(進度對話框-圓形進度條) xml


Java代碼  htm

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:(進度對話框-長方形進度條) get


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);
原文: http://www.2cto.com/kf/201109/104691.html
相關文章
相關標籤/搜索