欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android Alertdialog(實(shí)現(xiàn)警告對(duì)話框)

 更新時(shí)間:2016年11月23日 09:02:56   作者:潘侯爺  
本篇文章主要介紹了Android Dialog對(duì)話框,具體實(shí)現(xiàn)了警告對(duì)話框的效果,有需要的可以了解一下。

在Android開發(fā)中,我們經(jīng)常會(huì)需要在Android界面上彈出一些對(duì)話框,比如詢問(wèn)用戶或者讓用戶選擇。這些功能我們叫它Android Dialog對(duì)話框,AlertDialog實(shí)現(xiàn)方法為建造者模式。下面我們模擬卸載應(yīng)用程序時(shí)彈出的最為普通的警告對(duì)話框,如下圖:

layout布局界面代碼示例:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="match_parent"
  android:layout_height="match_parent">
  <Button
    android:text="卸載"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:onClick="show"
    android:id="@+id/button" />
</LinearLayout>

Java實(shí)現(xiàn)代碼:

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;
/**
 * Created by panchengjia on 2016/11/21.
 */
public class AlertDialogDemo extends AppCompatActivity {
  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.alterdialog);
  }
  public void show(View v){
    //實(shí)例化建造者
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    //設(shè)置警告對(duì)話框的標(biāo)題
    builder.setTitle("卸載");
    //設(shè)置警告顯示的圖片
//    builder.setIcon(android.R.drawable.ic_dialog_alert);
    //設(shè)置警告對(duì)話框的提示信息
    builder.setMessage("確定卸載嗎");
    //設(shè)置”正面”按鈕,及點(diǎn)擊事件
    builder.setPositiveButton("確定", new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
        Toast.makeText(AlertDialogDemo.this,"點(diǎn)擊了確定按鈕",Toast.LENGTH_SHORT).show();
      }
    });
    //設(shè)置“反面”按鈕,及點(diǎn)擊事件
    builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
        Toast.makeText(AlertDialogDemo.this,"點(diǎn)擊了取消按鈕",Toast.LENGTH_SHORT).show();
      }
    });
    //設(shè)置“中立”按鈕,及點(diǎn)擊事件
    builder.setNeutralButton("等等看吧", new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
        Toast.makeText(AlertDialogDemo.this,"點(diǎn)擊了中立按鈕",Toast.LENGTH_SHORT).show();
      }
    });
    //顯示對(duì)話框
    builder.show();
  }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論