Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Theme on ProgressDialog make it fullscreen

rookie android dev here. I have a problem with some ProgressDialog in an AsyncTask.

I want to apply a theme when I create a ProgressDialog, but when I apply it, the dialog just go fullscreen and my activity is hidden. When i remove the theme at instantiation, it's normal.

I just want to know why.

Here is my class with the AsyncTask :

public class Synchronize {

private static AppManager       app = AppManager.getInstance();

public void Synchronise() {
}

AsyncTask<Void, Void, Boolean> task = new AsyncTask<Void, Void, Boolean>() {

    private ProgressDialog  pd;

    @Override
    protected void onPreExecute() {;
        pd = new ProgressDialog(app.m_AppContext, android.R.style.Theme_Black);
        pd.setTitle("Veulliez patienter");
        pd.setMessage("Synchronisation en cours...");
        pd.setCancelable(false);
        pd.setIndeterminate(true);
        pd.show();
    }

    @Override
    protected Boolean doInBackground(Void... arg0) {
        try {
            //Synchronisation
            Thread.sleep(2000);
            Log.d("DEBUG","sync en cours");
        } catch (InterruptedException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    @Override
    protected void onPostExecute(Boolean result) {
        pd.dismiss();
        if (result)
            Toast.makeText(app.m_AppContext, "Synchronisation terminé avec succès", Toast.LENGTH_SHORT).show();
        else
            Toast.makeText(app.m_AppContext, "La synchronisation a échoué", Toast.LENGTH_SHORT).show();
        Log.d("DEBUG","SYNC DONE");
    }
};

public void startSync() {
    if (app.m_bIsOnline)
        task.execute((Void[])null);
    else
        Toast.makeText(app.m_AppContext, "Mode offline. Synchronisation impossible", Toast.LENGTH_SHORT).show();            
}

}

Thanks for help.

like image 910
Bernie Avatar asked Nov 12 '22 00:11

Bernie


1 Answers

You need to change style parent to dialog. For example:

<style name="AppTheme.Light" parent="Theme.AppCompat.Dialog" >
        <item name="colorAccent">@color/theme_color</item>
        <item name ="android:background">@color/theme_background_light</item>
        <item name = "android:textColor">@color/black</item>
</style>
like image 92
otopba Avatar answered Nov 15 '22 13:11

otopba