ProgressDialog drehender Kreis

Lesezeit: 4 Minuten

Ich möchte ProgressDialog so implementieren, ohne zusätzlichen Frame.:
Bild

Aber ich hole mir diese. Wie könnte ich das ändern?

Geben Sie hier die Bildbeschreibung ein

Hier ist mein Code für ProgressDialog. Danke im Voraus

private ProgressDialog mProgressDialog;
   ............
   mProgressDialog = new ProgressDialog(activity);
   mProgressDialog.setIndeterminate(false);
   mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
   ............
    public class ProgressTask extends AsyncTask <Fragment,Void,Fragment>{
            @Override
            protected void onPreExecute(){
                mProgressDialog.show();
            }

            @Override
            protected Fragment doInBackground(Fragment... arg0) {   
                    //my stuff is here
            }

            @Override
            protected void onPostExecute(Fragment result) {
                   mProgressDialog.dismiss();
            }
        }

  • Sie können dies zum Erstellen benutzerdefinierter Dialoge ausprobieren: stackoverflow.com/a/26821095/1554031

    – Satisch

    8. November 2014 um 19:41 Uhr

  • Diese Antwort hat bei mir funktioniert stackoverflow.com/questions/21957263/…

    – Dharmita bhatt

    7. Juni 2016 um 6:40 Uhr

Benutzer-Avatar
Jayyrus

Wechseln Sie einfach von ProgressDialog zu ProgressBar im Layout:

res/layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        //Your content here
     </LinearLayout>

        <ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:visibility="gone"
            android:indeterminateDrawable="@drawable/progress" >
        </ProgressBar>
</RelativeLayout>

src/yourPackage/YourActivity.java

public class YourActivity extends Activity{

private ProgressBar bar;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout);
    bar = (ProgressBar) this.findViewById(R.id.progressBar);
    new ProgressTask().execute();
}
private class ProgressTask extends AsyncTask <Void,Void,Void>{
    @Override
    protected void onPreExecute(){
        bar.setVisibility(View.VISIBLE);
    }

    @Override
    protected Void doInBackground(Void... arg0) {   
           //my stuff is here
    }

    @Override
    protected void onPostExecute(Void result) {
          bar.setVisibility(View.GONE);
    }
}
}

drawable/progress.xml Dies ist ein Brauch ProgressBar die ich verwende, um die Standardfarben zu ändern.

<?xml version="1.0" encoding="utf-8"?>

<!-- 
    Duration = 1 means that one rotation will be done in 1 second. leave it.
    If you want to speed up the rotation, increase duration value. 
    in example 1080 shows three times faster revolution. 
    make the value multiply of 360, or the ring animates clunky 
-->
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:duration="1"
    android:toDegrees="360" >

    <shape
        android:innerRadiusRatio="3"
        android:shape="ring"
        android:thicknessRatio="8"
        android:useLevel="false" >
        <size
            android:height="48dip"
            android:width="48dip" />

        <gradient
            android:centerColor="@color/color_preloader_center"
            android:centerY="0.50"
            android:endColor="@color/color_preloader_end"
            android:startColor="@color/color_preloader_start"
            android:type="sweep"
            android:useLevel="false" />
    </shape>

</rotate>

  • danke für die Antwort. Was soll ich in den Drawable-Ordner legen? (welche Fortschrittsdatei ist?)

    – Andreas Rahimov

    23. März 2013 um 11:11 Uhr

  • Was sind die Farbcodewerte für color_preloader_center, color_preloader_end und color_preloader_start?

    – Sankar V

    20. August 2013 um 9:14 Uhr

  • Danke für diese Antwort 🙂 Gibt es eine Möglichkeit, es schneller drehen zu lassen?

    – Maximosaik

    12. Dezember 2013 um 8:29 Uhr

  • @SankarV Ich habe #000000 #000000 #ff56a9c7 verwendet

    – Odysseus

    21. Juli 2014 um 16:37 Uhr

  • Ich habe den Wert im Größen-Tag sowohl für die Höhe als auch für die Breite in der Datei drawable/progress.xml geändert, aber es hat keine Auswirkungen. Irgendwelche Ideen?

    – Dekan

    7. März 2016 um 6:17 Uhr

Setzen Sie dieses XML, um nur das Rad anzuzeigen:

<ProgressBar
    android:indeterminate="true"
    android:id="@+id/marker_progress"
    style="?android:attr/progressBarStyle"
    android:layout_height="50dp" />

Benutzer-Avatar
jp093121

Ich benutzte View.INVISIBLE und View.VISIBLE und die ProgressBar würde langsam blinken, anstatt ständig sichtbar zu sein, umgeschaltet View.GONE und View.VISIBLE und es funktioniert perfekt

Benutzer-Avatar
Dilip Lohar

ProgressBar-Dialog – Sie müssen nicht ständig benutzerdefinierten progressBar-Code schreiben, eine Klasse unten erstellen und verwenden

public class DProgressbar {
    Dialog progressDialog ;
    public DProgressbar(Context context) {
        progressDialog = new Dialog(context);
        progressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        progressDialog.setContentView(R.layout.dialog_api_loading);
        progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        progressDialog.setCancelable(false);
    }

    public void show(){
        progressDialog.show();
    }

    public void dismiss(){
        progressDialog.dismiss();
    }

}

R.layout.dialog_api_loading

  <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:cardCornerRadius="@dimen/size_10">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:orientation="horizontal"
        android:padding="20dp">
<ProgressBar
            android:layout_width="@dimen/size_20"
            android:layout_height="@dimen/size_20" />
            <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginHorizontal="@dimen/txt_distance_5"
            android:gravity="center"
            android:text="Loading..." />
    </LinearLayout>
</androidx.cardview.widget.CardView>

Benutzer-Avatar
code_geek

Versuche dies………

ProgressDialog pd1;
pd1=new ProgressDialog(<current context reference here>);
pd1.setMessage("Loading....");
pd1.setCancelable(false);
pd1.show();

Ablehnen….

if(pd1!=null)
 pd1.dismiss(); 

1158430cookie-checkProgressDialog drehender Kreis

This website is using cookies to improve the user-friendliness. You agree by using the website further.

Privacy policy