溫馨提示×

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

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

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

發(fā)布時(shí)間:2021-06-29 15:07:47 來(lái)源:億速云 閱讀:114 作者:Leah 欄目:移動(dòng)開(kāi)發(fā)

Android中怎么實(shí)現(xiàn)一個(gè)對(duì)話框形式的進(jìn)度條功能,相信很多沒(méi)有經(jīng)驗(yàn)的人對(duì)此束手無(wú)策,為此本文總結(jié)了問(wèn)題出現(xiàn)的原因和解決方法,通過(guò)這篇文章希望你能解決這個(gè)問(wèn)題。

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>

看完上述內(nèi)容,你們掌握Android中怎么實(shí)現(xiàn)一個(gè)對(duì)話框形式的進(jìn)度條功能的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(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