1

我用谷歌搜索了很多,甚至解决了这个网站的许多问题,但我就是找不到解决问题的方法。

我想创建一个如下所示的进度对话框。但我不明白该怎么做..我尝试过创建一个自定义进度对话框但是..你只能修改内部微调器外观..在我的如果我想修改它的布局...我怎样才能实现...????

到目前为止,我已经尝试了以下...

public class nextclass extends Activity {

    Thread t;
    ProgressBar dia;

    private ProgressDialog progressDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        MainActivity.progressDialog.dismiss();
        setContentView(R.layout.nextclassview);
    //  requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

        ((Button) findViewById(R.id.button1))
                .setOnClickListener(new OnClickListener() {

                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        // progressDialog = findViewById(R.id.progressBar1);

                        new AuthenticateUserTask().execute();
                    }
                });
    }

    private class AuthenticateUserTask extends AsyncTask<Void, Void, String> {

        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();

            progressDialog = ProgressDialog.show(
                    nextclass.this, "","Sucessful", true);
/*            progressDialog.setIndeterminate(true);

            progressDialog.setIndeterminateDrawable(getResources()
                    .getDrawable(R.layout.customspinner));
*/


            progressDialog = ProgressDialog.show(nextclass.this, "",
                    "Processing....", true);
            progressDialog.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

        }

        protected void onPostExecute(String s) {
            if (progressDialog.isShowing())
                progressDialog.dismiss();

            Intent my = new Intent(getApplicationContext(), CountTime.class);
            startActivity(my);

        }

        @Override
        protected String doInBackground(Void... params) {
            // TODO Auto-generated method stub
            try {
                Thread.sleep(2000);![custom spinner][2]
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    }
}

在此处输入图像描述

4

2 回答 2

1

有关如何创建自定义对话框的详细信息,请参阅此链接

WindowManager.LayoutParams WMLP = dialog.getWindow().getAttributes();


     WMLP.x = 100;   //x position
     WMLP.y = 100;   //y position

     dialog.getWindow().setAttributes(WMLP);

Edit2: 使用您的代码创建一个对话框活动示例如下所示

public class DialogActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.setTitle(" ");
        alertDialog.setMessage("");
        alertDialog.setIcon(R.drawable.icon);
        alertDialog.setButton("Accept", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {                
            }
        });
        alertDialog.setButton2("Deny", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
            }
        });
        alertDialog.show();
    }
}

并在 android 清单文件中

android:theme="@android:style/Theme.Translucent.NoTitleBar"

或者

AlertDialog.Builder builder = new AlertDialog.Builder(
                    new ContextThemeWrapper(context, R.style.popup_theme));

在值文件夹中:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="back_color">#ffffffff</color>
<style name="popup_theme" parent="@android:style/Theme.Translucent.NoTitleBar">
    <item name="android:windowBackground">@color/back_color</item>
    <item name="android:colorBackground">@color/back_color</item>
</style>
于 2012-10-25T07:45:33.717 回答
0

为此,您需要在 anim 文件夹中有一个旋转动画:

<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@anim/linear_interpolator"
>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="51%"
android:repeatCount="infinite"
android:duration="800" />

</set>

在 XML 中创建一个图像视图:

      <ImageView
       android:id="@+id/loading"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_below="@+id/splash"
       android:layout_centerInParent="true"
       android:layout_gravity="center_horizontal"
       android:layout_marginTop="10dp"
       android:background="@drawable/load_spinner" />

使用以下代码:

       Animation mRotateAnim;
       ImageView mImgVwRotatingImage;
           mImgVwRotatingImage = (ImageView) findViewById(R.id.loading);
       mRotateAnim = AnimationUtils.loadAnimation(this, R.anim.rotate_anim);


private class splashAsync extends AsyncTask<Void, Void, Void> {
    protected void onPreExecute() {
        mImgVwRotatingImage.startAnimation(mRotateAnim);
    }

    protected Void doInBackground(Void... params) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return null;
    }

    protected void onPostExecute(Void v) {
        startActivity(new Intent(first.this, second.class));
        finish();
    }
}
于 2012-10-25T08:03:58.180 回答