Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中创建半透明进度对话框_Android - Fatal编程技术网

如何在android中创建半透明进度对话框

如何在android中创建半透明进度对话框,android,Android,我在谷歌上搜索了很多,甚至浏览了很多关于这个网站的问题,但我就是找不到解决问题的方法 我想创建一个如下所示的进度对话框。但我不知道如何创建。我尝试创建一个自定义进度对话框,但..使用该对话框,您只能修改内部微调器的外观..在我的情况下,我想修改其布局…我如何实现 到目前为止,我已经尝试了以下方法 public class nextclass extends Activity { Thread t; ProgressBar dia; private ProgressDi

我在谷歌上搜索了很多,甚至浏览了很多关于这个网站的问题,但我就是找不到解决问题的方法

我想创建一个如下所示的进度对话框。但我不知道如何创建。我尝试创建一个自定义进度对话框,但..使用该对话框,您只能修改内部微调器的外观..在我的情况下,我想修改其布局…我如何实现

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

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;
        }
    }
}
public类nextclass扩展活动{
螺纹t;
进度条直径;
私有进程对话;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
MainActivity.progressDialog.Disclose();
setContentView(R.layout.nextclassview);
//requestWindowFeature(Window.FEATURE\u不确定\u进度);
((按钮)findViewById(R.id.button1))
.setOnClickListener(新的OnClickListener(){
公共void onClick(视图v){
//TODO自动生成的方法存根
//progressDialog=findViewById(R.id.progressBar1);
新建AuthenticateUserTask().execute();
}
});
}
私有类AuthenticateUserTask扩展了AsyncTask{
@凌驾
受保护的void onPreExecute(){
//TODO自动生成的方法存根
super.onPreExecute();
progressDialog=progressDialog.show(
nextclass.this,“,”successful“,true);
/*progressDialog.setUndeterminate(true);
progressDialog.setIndeterminatedRavable(getResources()
.getDrawable(R.layout.customspinner));
*/
progressDialog=progressDialog.show(nextclass.this,“,
“处理…”,正确);
progressDialog.getWindow().setLayout(LayoutParams.FILL\u父级,LayoutParams.FILL\u父级);
}
受保护的void onPostExecute(字符串s){
if(progressDialog.isShowing())
progressDialog.disclose();
Intent my=newintent(getApplicationContext(),CountTime.class);
星触觉;
}
@凌驾
受保护字符串doInBackground(无效…参数){
//TODO自动生成的方法存根
试一试{
线程。睡眠(2000);![自定义微调器][2]
}捕捉(中断异常e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
返回null;
}
}
}

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

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>

#ffffffff
@颜色/背色
@颜色/背色
有关如何创建自定义对话框的详细信息,请参阅

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>

#ffffffff
@颜色/背色
@颜色/背色

为此,需要在动画文件夹中设置旋转动画,如下所示:

<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();
    }
}
动画mRotateAnim;
图像视图mimgvw旋转图像;
MIMGVRotatingImage=(ImageView)findViewById(R.id.loading);
mRotateAnim=AnimationUtils.loadAnimation(这是R.anim.rotate\u anim);
私有类splashAsync扩展了AsyncTask{
受保护的void onPreExecute(){
MIMGVRotatingImage.startAnimation(mRotateAnim);
}
受保护的Void doInBackground(Void…参数){
试一试{
睡眠(1000);
}捕捉(中断异常e){
e、 printStackTrace();
}
返回null;
}
受保护的void onPostExecute(void v){
startActivity(新意图(第一、本、二等));
完成();
}
}

为此,需要在动画文件夹中设置旋转动画,如下所示:

<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();
    }
}
动画mRotateAnim;
图像视图mimgvw旋转图像;
MIMGVRotatingImage=(ImageView)findViewById(R.id.loading);
mRotateAnim=AnimationUtils.loadAnimation(这是R.anim.rotate\u anim);
私有类splashAsync扩展了AsyncTask{
受保护的void onPreExecute(){
MIMGVRotatingImage.startAnimation(mRotateAnim);
}
受保护的Void doInBackground(Void…参数){
试一试{
睡眠(1000);
}捕捉(中断异常e){
e、 printStackTrace();
}
返回null;
}
受保护的void onPostExecute(void v){
startActivity(新意图(第一、本、二等));
完成();
}
}

不工作…我希望进度对话框只占屏幕的80%…屏幕的其余部分可供用户使用…例如,右上角的按钮是一个自定义注销按钮..应该可以单击..我想您可以在自定义对话框中包括注销按钮和其他视图,并为其提供背景图像或颜色信息技术使对话框100%显示在屏幕上,或者你可以检查我编辑的答案,使对话框显示在某个位置,你也可以设置其他属性。好的..现在唯一的问题是对话框不透明..我如何使它透明..我使自定义对话框背景透明,但不起作用..嗯,我猜是所显示的是因为它有一个黑色,alpha值小于60,我想不确定你能不能编辑并放置一个屏幕截图作为它的外观