溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

Android中如何實(shí)現(xiàn)一個(gè)對(duì)話框形式的進(jìn)度條功能

發(fā)布時(shí)間:2022-04-08 15:58:21 來(lái)源:億速云 閱讀:223 作者:iii 欄目:編程語(yǔ)言

這篇文章主要介紹了Android中如何實(shí)現(xiàn)一個(gè)對(duì)話框形式的進(jìn)度條功能的相關(guān)知識(shí),內(nèi)容詳細(xì)易懂,操作簡(jiǎn)單快捷,具有一定借鑒價(jià)值,相信大家閱讀完這篇Android中如何實(shí)現(xiàn)一個(gè)對(duì)話框形式的進(jìn)度條功能文章都會(huì)有所收獲,下面我們一起來(lái)看看吧。

MainActivity代碼如下:

package com.example.myapplication;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  ProgressDialog prodialog;
  Button show;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    show = (Button) findViewById(R.id.show);
    show.setOnClickListener(this);
  }
  @Override
  public void onClick(View view) {
    prodialog = new ProgressDialog(MainActivity.this);
    prodialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    prodialog.setTitle("億速云");
    prodialog.setMessage("jb51");
    prodialog.setIcon(R.mipmap.ic_launcher);
    //設(shè)計(jì)進(jìn)度條屬性
    prodialog.setMax(100);
    prodialog.incrementProgressBy(50);
    //明確顯示進(jìn)度
    prodialog.setIndeterminate(false);
    prodialog.setButton(DialogInterface.BUTTON_POSITIVE,"確定",
    new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialogInterface, int i) {
        Toast.makeText(MainActivity.this,"hello",Toast.LENGTH_LONG).show();
      }
    });
    prodialog.setCancelable(true);
    prodialog.show();
  }
}

布局文件:

<?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:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  android:paddingBottom="@dimen/activity_vertical_margin"
  tools:context="com.example.myapplication.MainActivity">
  <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="顯示進(jìn)度天對(duì)話框"
    android:id="@+id/show"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />
</RelativeLayout>

關(guān)于“Android中如何實(shí)現(xiàn)一個(gè)對(duì)話框形式的進(jìn)度條功能”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對(duì)“Android中如何實(shí)現(xiàn)一個(gè)對(duì)話框形式的進(jìn)度條功能”知識(shí)都有一定的了解,大家如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI