我遇到過ProgressDialog
已被棄用。除了ProgressBar
之外,還有其他替代選擇。 我正在使用android studio版本2.3.3。ProgressDialog不推薦使用。替代方法是什麼?
ProgressDialog progressDialog=new ProgressDialog(this);
progressDialog.show();
我遇到過ProgressDialog
已被棄用。除了ProgressBar
之外,還有其他替代選擇。 我正在使用android studio版本2.3.3。ProgressDialog不推薦使用。替代方法是什麼?
ProgressDialog progressDialog=new ProgressDialog(this);
progressDialog.show();
ProgressBar是ProgressDialog的最佳選擇。 指示操作進度的用戶界面元素。
欲瞭解更多信息請參閱本文檔谷歌:https://developer.android.com/reference/android/widget/ProgressBar.html
他說「除了進度條」。 – creativecreatorormaybenot
由於在documentation page替代提到的是ProgressBar
。 ProgressDialog
的外觀可以通過將ProgressBar
放入AlertDialog
來複制。
你仍然可以使用它,但Android不希望你使用它,這就是它被棄用的原因。所以你應該考慮以另一種方式解決你的問題,比如將ProgressBar
嵌入你的Layout
。
因爲我們仍然可以使用它,它會崩潰在api級別26+還是會正常工作(與較低的api相同)? –
此類在API級別26中已棄用。ProgressDialog是一種模式 對話框,可防止用戶與應用程序進行交互。取而代之的是使用此類的 ,您應該使用進度指示器,如 ProgressBar,它可以嵌入到應用程序的用戶界面中。或者, 您可以使用通知來通知用戶任務的進度。 link
它在Android O
因爲Google
新的UI標準
「此類在API級別26中已棄用」,而不是日期。他們不希望你再使用它。是的,這是由於新的UI標準,但它們適用於每個API級別...... – creativecreatorormaybenot
「由於Google新的UI標準,它在Android O中已棄用」 - 請鏈接新的UI標準 –
也許這guide可以幫助你過時了。
通常我更喜歡使用指示器來定製AlertDialogs。它解決了諸如App視圖自定義之類的問題。
是的,API level 26
已棄用,建議您只效法progressbar
。
使用此代碼,用於創建編程:
RelativeLayout的佈局= findViewById(R.id。顯示); //在這裏指定根佈局ID
(或)
RelativeLayout的佈局= findViewById(本);
progressBar = new ProgressBar(youractivity.this,null,android.R.attr.progressBarStyleLarge);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(100,100);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
layout.addView(progressBar,params);
progressBar.setVisibility(View.VISIBLE); //To show ProgressBar
progressBar.setVisibility(View.GONE); // To Hide ProgressBar
要禁用,你只需要添加以下 代碼的用戶交互
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
得到用戶的互動活動,你只需要添加以下代碼
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
只是以供將來參考,改變android.R.attr.progressBarStyleSmall
到android.R.attr.progressBarStyleHorizontal
。
此以下行代碼的工作僅在高於21 API progressBar.setProgressTintList(ColorStateList.valueOf(Color.RED));
解決方案2:另一種方法
<ProgressBar
android:id="@+id/progressbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:max="100"
android:backgroundTint="@color/white"
android:layout_below="@+id/framelauout"
android:indeterminateTint="#1a09d6"
android:layout_marginTop="-7dp"/>
Activity.java
progressBar = (ProgressBar) findViewById(R.id.progressbar);
`progressBar.setVisibility(View.VISIBLE);`// To Show ProgressBar
`progressBar.setVisibility(View.INVISIBLE);` //To Hide ProgressBar
欲瞭解更多詳情:1.Reference one 2.Reference Two
我希望這可以幫助你。
謝謝大家的upvote。 –
爲第一種方法,如何以編程方式添加或顯示progressBar – usman
@usman請檢查我的更新答案...如果它是有用的donot忘記upvote。 –
那麼,如果你真的想要去違背自己的意願,仍然可以使用Sweet Alert Dialog或創建一個你自己的。
progress_dialog_layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="64dp" >
<ProgressBar
android:id="@+id/progressBar2"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<TextView
android:gravity="center|left"
android:id="@+id/textView9"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="@color/black"
android:textSize="18sp"
android:text="Downloading data. Please wait.." />
</TableRow>
</RelativeLayout>
Java代碼:
AlertDialog b;
AlertDialog.Builder dialogBuilder;
public void ShowProgressDialog() {
dialogBuilder = new AlertDialog.Builder(DataDownloadActivity.this);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View dialogView = inflater.inflate(R.layout.progress_dialog_layout, null);
dialogBuilder.setView(dialogView);
dialogBuilder.setCancelable(false);
b = dialogBuilder.create();
b.show();
}
public void HideProgressDialog(){
b.dismiss();
}
我在SweetAlertDialog的製作環境中遇到過可怕的經歷,因爲它在窗口之間泄漏,所以非常謹慎。 – Jeremy
它可以幫助其他人。
很多熱門的應用有不同的方法來顯示的像網絡請求,文件加載等加載微調什麼進展沒有顯示多少內容已經被加載或剩餘加載。有一段時間的不確定性是壞UI/UX的觀點。很多流行的應用程序(Facebook,Linkedin等)已經通過首先顯示裸露的骨骼UI顯示解決了這個問題。然後,加載的內容逐漸填充在屏幕上。
我已經使用shimmer爲我的應用程序來解決這個問題。
有關於這這將是其他人
我用DelayedProgressDialog從https://github.com/Q115/DelayedProgressDialog它確實一樣ProgressDialog與延遲額外的好處,如果必要的有益的好article。
使用它的是AndroidØ前同樣ProgressDialog:
DelayedProgressDialog progressDialog = new DelayedProgressDialog();
progressDialog.show(getSupportFragmentManager(), "tag");
ProgressDialog
API等級26已被否決。
指的是在由較新的被替換的過程中的功能或元件。"Deprecated"
ProgressDialog是一個模態對話框,這防止用戶從與 該應用進行交互。您應該使用像
ProgressBar
這樣的進度 指標,而不是使用此課程,該指標可以嵌入您應用的用戶界面 。
優勢
我個人說,ProgressBar
擁有兩個邊緣。 ProgressBar
是指示操作進度的用戶界面元素。以非中斷的方式向用戶顯示進度條。在應用的用戶界面中顯示進度條。
您可以簡單地爲您的進度條設計一個xml接口,並將其作爲視圖傳遞給AlertDialog,然後隨時顯示或關閉對話框。
progress.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:padding="13dp"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:id="@+id/loader"
android:layout_marginEnd="5dp"
android:layout_width="45dp"
android:layout_height="45dp" />
<TextView
android:layout_width="wrap_content"
android:text="Loading..."
android:textAppearance="?android:textAppearanceSmall"
android:layout_gravity="center_vertical"
android:id="@+id/loading_msg"
android:layout_toEndOf="@+id/loader"
android:layout_height="wrap_content" />
</LinearLayout>
顯示的進度對話框中的代碼的代碼。只需複製此代碼並將其粘貼到片段即可。
private void setDialog(boolean show){
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
//View view = getLayoutInflater().inflate(R.layout.progress);
builder.setView(R.layout.progress);
Dialog dialog = builder.create();
if (show)dialog.show();
else dialog.dismiss();
}
,每當你想顯示progressdialog並通過真正作爲參數來顯示它或假關閉該對話框然後,只需調用該方法。
無法解析獲取活動 –
設置視圖需要API級別21.所以沒有準備好api19 –
@Alok Rajasukumaran它似乎你正在使用活動,只需將它替換爲'this',以便它看起來像這樣'AlertDialog.Builder builder =新的AlertDialog.Builder(this);'。請確保你正在複製正確的代碼。 – DevMike
您可以使用SpotDialog使用wasabeef你可以找到從以下鏈接的完整的教程庫:
請我answer.i希望這將幫助你 –
[ProgressDialog可能的重複被棄用](https://stackoverflow.com/questions/45351127/progressdialog-is-deprecated) –