欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

進(jìn)度條ProgressBar及ProgressDialog(實(shí)例)

 更新時間:2017年07月03日 15:36:09   投稿:jingxian  
下面小編就為大家?guī)硪黄M(jìn)度條ProgressBar及ProgressDialog(實(shí)例)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

廢話不多說,直接上代碼

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是進(jìn)度條組件,通常用于向用戶展示某個耗時操作完成的進(jìn)度,而不讓用戶感覺是程序失去了響應(yīng),從而更好地提升用戶界面的友好性
  課程目標(biāo):
      1、制定ProgressBar顯示風(fēng)格(系統(tǒng)默認(rèn))
      2、ProgressBar的分類
      水平進(jìn)度條,能精確顯示,圓圈進(jìn)度條,不精確顯示
  3、標(biāo)題上ProgressBar的設(shè)置
  4、ProgressBar的關(guān)鍵屬性
  5、ProgressBar的關(guān)鍵方法
  6、ProgressDiglog的基礎(chǔ)使用
  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);
//    啟用窗口特征,啟用帶進(jìn)度的進(jìn)度條和不帶進(jìn)度的進(jìn)度條,
    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();/*獲取第一進(jìn)度*/
    int second=progressBar3.getSecondaryProgress();/*獲取第二進(jìn)度*/
    int max=progressBar3.getMax();/*獲取最大進(jìn)度*/
    textView.setText("第一進(jìn)度條百分比"+(int)((first/(float)max)*100)+"%"+"第二進(jìn)度條百分比"+(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);
//        設(shè)置顯示風(fēng)格
        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
//          設(shè)置標(biāo)題
        progressDialog.setTitle("慕課網(wǎng)");
//        設(shè)置對話框的內(nèi)容
        progressDialog.setMessage("歡迎大家支持慕課網(wǎng)");
//       設(shè)置圖標(biāo)
        progressDialog.setIcon(R.mipmap.ic_launcher);

       /*設(shè)置關(guān)于進(jìn)度條的一些屬性*/
//        設(shè)置最大進(jìn)度
        progressDialog.setMax(100);
//        設(shè)置初始化已經(jīng)增長的進(jìn)度
        progressDialog.incrementProgressBy(50);
//        設(shè)置進(jìn)度條明確顯示進(jìn)度
        progressDialog.setIndeterminate(false);

        /* 設(shè)定一個確定按鈕*/
        progressDialog.setButton(DialogInterface.BUTTON_POSITIVE,"確定", new Dialog.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            Toast.makeText(MainActivity.this,"歡迎大家支持慕課網(wǎng)",Toast.LENGTH_SHORT).show();
          }
        });
//        是否可以通過返回按鈕來取消對話框
        progressDialog.setCancelable(true);
//        顯示ProgressDialog
        progressDialog.show();
    }
    textView.setText("第一進(jìn)度條百分比"+(int)((progressBar3.getProgress()/(float)progressBar3.getMax())*100)+"%"+"第二進(jìn)度條百分比"+(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="進(jìn)度"
    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/顯示進(jìn)度條"
    android:id="@+id/show"
    android:layout_below="@+id/progressBar2"
    android:layout_alignParentEnd="true" />
</RelativeLayout>
  <!-- ProgressBar關(guān)鍵屬性
  1.android:max -&#45;&#45;最大顯示進(jìn)度
  2.android:progress -&#45;&#45;第一顯示進(jìn)度
  3.android:secondaryProgress-&#45;&#45;第二顯示進(jìn)度
  4.android:isdeterminate -&#45;&#45;設(shè)置是否精確顯示(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>

以上這篇進(jìn)度條ProgressBar及ProgressDialog(實(shí)例)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android動態(tài)添加view的方法示例

    Android動態(tài)添加view的方法示例

    本篇文章主要介紹了Android動態(tài)添加view的方法示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-10-10
  • Android Studio打包jar及aar包的方法

    Android Studio打包jar及aar包的方法

    這篇文章主要介紹了Android Studio打包jar及aar包的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-07-07
  • 利用Flutter實(shí)現(xiàn)背景圖片毛玻璃效果實(shí)例

    利用Flutter實(shí)現(xiàn)背景圖片毛玻璃效果實(shí)例

    Flutter沒有單獨(dú)的模糊處理容器,需要部件層層疊加實(shí)現(xiàn)模糊效果,下面這篇文章主要給大家介紹了關(guān)于利用Flutter實(shí)現(xiàn)背景圖片毛玻璃效果的相關(guān)資料,需要的朋友可以參考下
    2022-06-06
  • Flutter 滾動監(jiān)聽及實(shí)戰(zhàn)appBar滾動漸變的實(shí)現(xiàn)

    Flutter 滾動監(jiān)聽及實(shí)戰(zhàn)appBar滾動漸變的實(shí)現(xiàn)

    這篇文章主要介紹了Flutter 滾動監(jiān)聽及實(shí)戰(zhàn)appBar滾動漸變,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09
  • android 顯示gif圖片實(shí)例詳解

    android 顯示gif圖片實(shí)例詳解

    本文主要介紹android 顯示gif圖片的知識,這里整理相關(guān)資料及簡單實(shí)例代碼,有需要的小伙伴可以參考下
    2016-09-09
  • TabLayout實(shí)現(xiàn)ViewPager指示器的方法

    TabLayout實(shí)現(xiàn)ViewPager指示器的方法

    這篇文章主要為大家詳細(xì)介紹了TabLayout實(shí)現(xiàn)ViewPager指示器,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • Android中的SQLite數(shù)據(jù)庫簡介

    Android中的SQLite數(shù)據(jù)庫簡介

    SQLite是Android系統(tǒng)采用的一種開源的輕量級的關(guān)系型的數(shù)據(jù)庫。這篇文章主要介紹了Android中的SQLite數(shù)據(jù)庫簡介,需要的朋友可以參考下
    2017-03-03
  • 詳解Android使用@hide的API的方法

    詳解Android使用@hide的API的方法

    這篇文章主要介紹了詳解Android使用@hide的API的方法的相關(guān)資料,希望通過本文大家能理解掌握這部分內(nèi)容,需要的朋友可以參考下
    2017-09-09
  • Android自定義View實(shí)現(xiàn)loading動畫加載效果

    Android自定義View實(shí)現(xiàn)loading動畫加載效果

    項目開發(fā)中對Loading的處理是比較常見的,安卓系統(tǒng)提供的不太美觀,引入第三發(fā)又太麻煩,這時候自己定義View來實(shí)現(xiàn)這個效果。這篇文章主要介紹了Android自定義View實(shí)現(xiàn)loading動畫加載效果,需要的朋友可以參考下
    2017-03-03
  • Kotlin?Dispatchers協(xié)程調(diào)度器源碼深入分析

    Kotlin?Dispatchers協(xié)程調(diào)度器源碼深入分析

    Kotlin協(xié)程不是什么空中閣樓,Kotlin源代碼會被編譯成class字節(jié)碼文件,最終會運(yùn)行到虛擬機(jī)中。所以從本質(zhì)上講,Kotlin和Java是類似的,都是可以編譯產(chǎn)生class的語言,但最終還是會受到虛擬機(jī)的限制,它們的代碼最終會在虛擬機(jī)上的某個線程上被執(zhí)行
    2022-11-11

最新評論