国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

進度條ProgressBar及ProgressDialog(實例)

2019-10-22 18:33:04
字體:
來源:轉載
供稿:網友

廢話不多說,直接上代碼

Main代碼package processdemo.example.administrator.processbardemo;import android.app.Dialog;import android.app.ProgressDialog;import android.content.DialogInterface;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.util.Log;import android.view.View;import android.view.Window;import android.widget.Button;import android.widget.ProgressBar;import android.widget.TextView;import android.widget.Toast;public class MainActivity extends AppCompatActivity implements View.OnClickListener{  /*ProgressBar  簡介:ProgressBar是進度條組件,通常用于向用戶展示某個耗時操作完成的進度,而不讓用戶感覺是程序失去了響應,從而更好地提升用戶界面的友好性  課程目標:      1、制定ProgressBar顯示風格(系統默認)      2、ProgressBar的分類      水平進度條,能精確顯示,圓圈進度條,不精確顯示  3、標題上ProgressBar的設置  4、ProgressBar的關鍵屬性  5、ProgressBar的關鍵方法  6、ProgressDiglog的基礎使用  7、自定義ProgressBar樣式*/  private ProgressBar progressBar3;  private Button show;  private Button add;  private Button res;  private Button reset;  private TextView textView;  private ProgressDialog progressDialog;  @Override  protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);//    啟用窗口特征,啟用帶進度的進度條和不帶進度的進度條,    requestWindowFeature(Window.FEATURE_PROGRESS);    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);    setContentView(R.layout.activity_main);    setProgressBarVisibility(true);    setProgressBarIndeterminateVisibility(false);//    最大值為Max=10000;    //setProgress(600);    init();  }  private void init() {    ;    progressBar3= (ProgressBar) findViewById(R.id.progressBar3);    show= (Button) findViewById(R.id.show);    add= (Button) findViewById(R.id.add);    res= (Button) findViewById(R.id.res);    reset= (Button) findViewById(R.id.reset);    textView= (TextView) findViewById(R.id.textView);    int first=progressBar3.getProgress();/*獲取第一進度*/    int second=progressBar3.getSecondaryProgress();/*獲取第二進度*/    int max=progressBar3.getMax();/*獲取最大進度*/    textView.setText("第一進度條百分比"+(int)((first/(float)max)*100)+"%"+"第二進度條百分比"+(int)(second/(float)max*100)+"%");    add.setOnClickListener(this);    res.setOnClickListener(this);    reset.setOnClickListener(this);    show.setOnClickListener(this);  }  @Override  public void onClick(View v) {    switch (v.getId()){      case R.id.add:        progressBar3.incrementProgressBy(10);        progressBar3.incrementSecondaryProgressBy(10);        break;      case R.id.res:        progressBar3.incrementProgressBy(-10);        progressBar3.incrementSecondaryProgressBy(-10);        break;      case R.id.reset:        progressBar3.setProgress(50);        progressBar3.setSecondaryProgress(50);        break;      case R.id.show://        新建ProgressDialog對象        progressDialog=new ProgressDialog(MainActivity.this);//        設置顯示風格        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);//          設置標題        progressDialog.setTitle("慕課網");//        設置對話框的內容        progressDialog.setMessage("歡迎大家支持慕課網");//       設置圖標        progressDialog.setIcon(R.mipmap.ic_launcher);       /*設置關于進度條的一些屬性*///        設置最大進度        progressDialog.setMax(100);//        設置初始化已經增長的進度        progressDialog.incrementProgressBy(50);//        設置進度條明確顯示進度        progressDialog.setIndeterminate(false);        /* 設定一個確定按鈕*/        progressDialog.setButton(DialogInterface.BUTTON_POSITIVE,"確定", new Dialog.OnClickListener() {          @Override          public void onClick(DialogInterface dialog, int which) {            Toast.makeText(MainActivity.this,"歡迎大家支持慕課網",Toast.LENGTH_SHORT).show();          }        });//        是否可以通過返回按鈕來取消對話框        progressDialog.setCancelable(true);//        顯示ProgressDialog        progressDialog.show();    }    textView.setText("第一進度條百分比"+(int)((progressBar3.getProgress()/(float)progressBar3.getMax())*100)+"%"+"第二進度條百分比"+(int)(progressBar3.getSecondaryProgress()/(float)progressBar3.getMax()*100)+"%");  }}

layout中activity_main.xml代碼

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:tools="http://schemas.android.com/tools"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:paddingBottom="@dimen/activity_vertical_margin"  android:paddingLeft="@dimen/activity_horizontal_margin"  android:paddingRight="@dimen/activity_horizontal_margin"  android:paddingTop="@dimen/activity_vertical_margin"  tools:context="processdemo.example.administrator.processbardemo.MainActivity">  <ProgressBar    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:id="@+id/progressBar"    android:layout_alignParentTop="true"    android:layout_alignParentStart="true"    android:layout_marginTop="112dp" />  <ProgressBar    style="?android:attr/progressBarStyleSmall"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:id="@+id/progressBar2"    android:layout_centerVertical="true"    android:layout_alignParentEnd="true"    android:layout_marginEnd="256dp" />  <ProgressBar    style="@android:style/Widget.ProgressBar.Horizontal"    android:max="100"    android:progress="50"    android:secondaryProgress="80"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:id="@+id/progressBar3"    android:layout_alignParentBottom="true"    android:layout_alignStart="@+id/progressBar2"    android:layout_marginBottom="81dp"    android:layout_alignTop="@+id/res"    android:progressDrawable="@layout/progress"/><!--progressDrawable改變樣式-->  <ProgressBar    style="?android:attr/progressBarStyleLarge"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:id="@+id/progressBar4"    android:layout_above="@+id/reset"    android:layout_centerHorizontal="true" />  <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="@string/增加"    android:id="@+id/add"    android:layout_alignParentBottom="true"    android:layout_alignParentEnd="true" />  <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="@string/減少"    android:id="@+id/res"    android:layout_above="@+id/add"    android:layout_alignParentEnd="true" />  <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="@string/重置"    android:id="@+id/reset"    android:layout_alignBottom="@+id/progressBar3"    android:layout_alignParentEnd="true" />  <TextView    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="進度"    android:id="@+id/textView"    android:layout_below="@+id/progressBar"    android:layout_alignParentEnd="true" />  <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="@string/顯示進度條"    android:id="@+id/show"    android:layout_below="@+id/progressBar2"    android:layout_alignParentEnd="true" /></RelativeLayout>  <!-- ProgressBar關鍵屬性  1.android:max ---最大顯示進度  2.android:progress ---第一顯示進度  3.android:secondaryProgress---第二顯示進度  4.android:isdeterminate ---設置是否精確顯示(false為精確,true為不精確)-->

layout中progress.xml

<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent">  <item android:id="@android:id/background">    <shape>      <corners android:radius="5dip" />      <gradient        android:startColor="#76cf76"        android:centerColor="#125912"        android:centerY="0.75"        android:endColor="#212621"        android:angle="270"        />    </shape>  </item>  <item android:id="@android:id/secondaryProgress">    <clip>      <shape>        <corners android:radius="5dip" />        <gradient          android:startColor="#80b51638"          android:centerColor="#80a47d1a"          android:centerY="0.75"          android:endColor="#a066c3a7"          android:angle="270"          />      </shape>    </clip>  </item>  <item android:id="@android:id/progress">    <clip>      <shape>        <corners android:radius="5dip" />        <gradient          android:startColor="#a38c1c"          android:centerColor="#55a6b6"          android:centerY="0.75"          android:endColor="#b59826"          android:angle="270"          />      </shape>    </clip>  </item></layer-list>

以上這篇進度條ProgressBar及ProgressDialog(實例)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鲁甸县| 酉阳| 上栗县| 阿尔山市| 南和县| 沙雅县| 阿坝| 临邑县| 阜城县| 琼海市| 剑川县| 保亭| 武胜县| 疏勒县| 凉山| 华阴市| 斗六市| 河北区| 顺义区| 贵州省| 渭南市| 义乌市| 乌审旗| 安岳县| 高唐县| 定襄县| 胶州市| 洛南县| 织金县| 清河县| 高唐县| 永兴县| 南投县| 涿州市| 松阳县| 沧州市| 类乌齐县| 深圳市| 河曲县| 基隆市| 福鼎市|