如何创建自定义进度对话框(微调器)?

时间:2012-10-23 13:38:14

标签: android android-spinner

Sorry for the late update..but this is the kind of spinner layout I'm talking about我搜索了很多内容,甚至经历了很多网站问题,但我找不到解决问题的方法。

我想创建一个像下面那样的微调器。这只是我迄今为止所做的一个普通的旋转器。我尝试了各种微调器示例,但它们没有给我我想要的结果。

这是我的代码:

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;
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我没有看到您的代码中的任何Spinner。但无论如何,你可以使用下面的代码来制作自定义微调器。

在布局文件中:

    <Spinnerandroid:id="@+id/spinnerview"
android:layout_width="180dp"
android:layout_height="42dp"
android:layout_marginLeft="105dp"
android:layout_marginTop="45dp"
android:background="@drawable/spinner_back"
android:paddingLeft="5dp"
android:spinnerMode="dropdown"android:visibility="visible" />

在String.xml中:

<string-array name="spinner_array_environtment">
        <item>Test</item>
        <item>Production</item>
    </string-array>

OnCreate方法中的Java文件:

spinner_environment = (Spinner) findViewById(R.id.spinnerview);
            adapter = ArrayAdapter.createFromResource(this,
                    R.array.spinner_array_environtment, R.layout.spinner);
            adapter.setDropDownViewResource(R.layout.spinner);
            spinner_environment.setAdapter(adapter);

将新的spinner.xml文件添加到布局文件夹中:

在spinner.xml文件中:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/spinnerTarget"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="25dp"
    android:textColor="#4C4646" />

多数民众赞成!