package com.android_dialog; import android.app.Activity; import android.app.Dialog; import android.os.Bundle; import android.view.View; import android.widget.TextView; public class Main extends Activity { private Dialog progressDialog; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); findViewById(R.id.show_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { progressDialog = new Dialog(Main.this,R.style.progress_dialog); progressDialog.setContentView(R.layout.dialog); progressDialog.setCancelable(true); progressDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); TextView msg = (TextView) progressDialog.findViewById(R.id.id_tv_loadingmsg); msg.setText("加载中..."); progressDialog.show(); } }); findViewById(R.id.close_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { cancel(); } }); } public void cancel(){ progressDialog.dismiss(); } }
评论