2016-12-03 101 views
0

我如何完全自定義Android ProgressDialog?我想在對話框中使用橫向樣式,但使用AdMob橫幅廣告或矩形廣告。 根據我的說法,我必須爲對話框創建自定義樣式和資源文件。我怎樣才能做到這一點?如何自定義Android ProgressDialog?

但我想要水平進度條,因爲它是。

當前代碼:

 progressDialog.setTitle("Downloading..."); 

     progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 
     progressDialog.setMax(100); 
     progressDialog.setProgress(0); 
     progressDialog.show(); 
     progressDialog.setCancelable(true); 
+1

使用這個偉大的圖書館。 [材料對話](https://github.com/afollestad/material-dialogs) – Vall0n

+0

感謝Vall0n。有沒有什麼辦法可以做到這一點,而不使用任何第三方庫? – johndoe122

+0

從庫中複製代碼並對其進行自定義,簡單 –

回答

0

使用一個進度條,並在自定義XML視圖中顯示的AdMob中查看的使用警告對話框

 AlertDialog.Builder builderVal=new AlertDialog.Builder(this); 
     builderVal.setTitle("Loading") ; 
     View holder=View.inflate(mContext, R.layout.your_view.xml, null); 
     builderVal.setView(holder); 

     AdView xs = (AdView) holder.findViewById(R.id.admobView); 
     //use your admob view 
     ProgressBar pb = (ProgressBar)holder.findViewById(R.id.progressBar); 
     //use your progressbar 

     builderVal.show(); 

看到執行進度http://www.compiletimeerror.com/2013/09/android-progress-bar-example.html#.WEKou-Z9600

+0

非常感謝Peter! AdmobView給我錯誤。無法解析符號AdmobView。 – johndoe122

+0

解決admob,然後upvote – Mushirih

+0

看到編輯,它的AdView類 – Mushirih

0

你只必須使用setview方法進行佈局並將其充注到alertdialog。請檢查此鏈接here

final AlertDialog alertDialog2 = new AlertDialog.Builder(getActivity()).create(); 
     final View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.your_custom_layout, null); 
     alertDialog2.setView(dialogView); 

     Button cancelBtn= (Button) dialogView.findViewById(R.id.verifyBtn); 
     cancelBtn.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       alertDialog2.dismiss(); 
      } 
     }); 

     alertDialog2.show();