国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Android > 正文

Android實(shí)現(xiàn)退出界面彈出提示對(duì)話框

2019-10-22 18:18:34
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

根據(jù)之前學(xué)的Android對(duì)話框技術(shù),來(lái)實(shí)現(xiàn)下面一個(gè)效果:界面有一個(gè)"退出"按鈕,按下之后會(huì)彈出一個(gè)詢問(wèn)是否退出的提示對(duì)話框,單擊"不"按鈕,不退出游戲,單擊"是的"按鈕,將退出游戲。

接下來(lái)實(shí)現(xiàn)此實(shí)例:

res/layout/main.xml:

<?xml version="1.0" encoding="utf-8"?>  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:id="@+id/layout1"   android:gravity="center_horizontal"   >    <Button     android:id="@+id/button1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"      android:text="退出"/> </LinearLayout> 

MainActivity:

package com.example.test;    import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button;   public class MainActivity extends Activity {      @Override    public void onCreate(Bundle savedInstanceState) {      super.onCreate(savedInstanceState);      setContentView(R.layout.main);           Button button=(Button)findViewById(R.id.button1);     //為"退出"按鈕添加單擊事件監(jiān)聽器     button.setOnClickListener(new OnClickListener() {              @Override       public void onClick(View view) {         AlertDialog alert=new AlertDialog.Builder(MainActivity.this).create();         alert.setIcon(R.drawable.stop);         alert.setTitle("退出?");         alert.setMessage("真的要退出本軟件嗎?");         //添加取消按鈕         alert.setButton(DialogInterface.BUTTON_NEGATIVE,"不",new DialogInterface.OnClickListener() {                      @Override           public void onClick(DialogInterface dialog, int which) {             // TODO Auto-generated method stub                        }         });         //添加"確定"按鈕         alert.setButton(DialogInterface.BUTTON_POSITIVE,"是的", new DialogInterface.OnClickListener() {                      @Override           public void onClick(DialogInterface arg0, int arg1) {              finish();           }         });         alert.show();       }     });   }  }  

運(yùn)行結(jié)果如圖:

Android,對(duì)話框,Android提示對(duì)話框,Android彈出提示

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


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到Android開發(fā)頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 龙川县| 兰州市| 安图县| 壤塘县| 怀远县| 平安县| 开阳县| 儋州市| 沈丘县| 陆川县| 浠水县| 确山县| 宜春市| 乌拉特后旗| 鸡东县| 鄂托克前旗| 稷山县| 马公市| 巩留县| 邻水| 自贡市| 靖安县| 板桥市| 肃宁县| 桃江县| 古交市| 郯城县| 措美县| 永年县| 泰安市| 德格县| 中卫市| 原平市| 海丰县| 克拉玛依市| 封开县| 襄汾县| 城口县| 虹口区| 兰溪市| 白玉县|