android自訂對話方塊

來源:互聯網
上載者:User

主要代碼:

package cn.bzu.dialogcase;import android.os.Bundle;import android.app.Activity;import android.app.AlertDialog;import android.app.ProgressDialog;import android.content.DialogInterface;import android.view.LayoutInflater;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.support.v4.app.NavUtils;public class MainActivity extends Activity {@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);alertDialog.setTitle("登入提示").setMessage("這裡需要登入").setPositiveButton("確定", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// 點擊確定進入登入對話方塊// Inflator在android中建立了資源檔到對象的橋樑LayoutInflater layoutInflater = LayoutInflater.from(MainActivity.this);// 得到自訂的對話方塊View dialogView = layoutInflater.inflate(R.layout.dialog, null);// 建立對話方塊AlertDialog.Builder loginDialog = new AlertDialog.Builder(MainActivity.this);loginDialog.setTitle("登入框").setView(dialogView).setPositiveButton("確定",new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog,int which) {// 輸入完成後,點擊確定開始登入// 建立進度對話方塊final ProgressDialog progressDialog = ProgressDialog.show(MainActivity.this,"請等待","正在為你登入", true);new Thread() {@Overridepublic void run() {try {Thread.sleep(3000);} catch (InterruptedException e) {e.printStackTrace();} finally {progressDialog.dismiss();}}}.start();}}).setNegativeButton("取消",new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog,int which) {finish();// 如果點擊了取消按鈕則退出應用程式}}).create().show();}}).setNeutralButton("退出", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {finish();}}).create().show();}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {getMenuInflater().inflate(R.menu.activity_main, menu);return true;}}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.