午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術(shù)文章
文章詳情頁

android實(shí)現(xiàn)彈出提示框

瀏覽:164日期:2022-09-21 09:32:23

本文實(shí)例為大家分享了anadroid實(shí)現(xiàn)彈出提示框的具體代碼,供大家參考,具體內(nèi)容如下

提示框是利用AlertDialog實(shí)現(xiàn)的。

代碼:

(設(shè)置在button的點(diǎn)擊事件中)

new AlertDialog.Builder(MainActivity.this).setTitle('信息提示')//設(shè)置對(duì)話框標(biāo)題 .setMessage('是否需要更換xxx?') .setPositiveButton('是', new DialogInterface.OnClickListener() {//添加確定按鈕 @Override public void onClick(DialogInterface dialog, int which) {//確定按鈕的響應(yīng)事件,點(diǎn)擊事件沒寫,自己添加 } }).setNegativeButton('否', new DialogInterface.OnClickListener() {//添加返回按鈕 @Override public void onClick(DialogInterface dialog, int which) {//響應(yīng)事件,點(diǎn)擊事件沒寫,自己添加 } }).show();//在按鍵響應(yīng)事件中顯示此對(duì)話框 } });

實(shí)現(xiàn)效果:

android實(shí)現(xiàn)彈出提示框

完整代碼:

package com.example.myapplicationusealertdialog;import androidx.appcompat.app.AppCompatActivity;import android.app.AlertDialog;import android.content.DialogInterface;import android.os.Bundle;import android.view.View;import android.widget.Button;public class MainActivity extends AppCompatActivity { Button bnt; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); bnt = findViewById(R.id.button); bnt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new AlertDialog.Builder(MainActivity.this).setTitle('信息提示')//設(shè)置對(duì)話框標(biāo)題 .setMessage('是否需要更換xxx?') .setPositiveButton('是', new DialogInterface.OnClickListener() {//添加確定按鈕 @Override public void onClick(DialogInterface dialog, int which) {//確定按鈕的響應(yīng)事件 } }).setNegativeButton('否', new DialogInterface.OnClickListener() {//添加返回按鈕 @Override public void onClick(DialogInterface dialog, int which) {//響應(yīng)事件 } }).show();//在按鍵響應(yīng)事件中顯示此對(duì)話框 } }); }}

<?xml version='1.0' encoding='utf-8'?><LinearLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:app='http://schemas.android.com/apk/res-auto' xmlns:tools='http://schemas.android.com/tools' android:layout_width='match_parent' android:layout_height='match_parent' tools:context='.MainActivity'> <Button android:layout_width='200dp' android:layout_marginLeft='100dp' android:layout_height='wrap_content' android:text='點(diǎn)擊' android: /></LinearLayout>

其實(shí)AlertDialog可以添加其他的功能選項(xiàng),比如在提示框里面綁定xml布局顯示,再比如定義多個(gè)選擇按鈕什么的,這些大家可以自行學(xué)習(xí)。

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

標(biāo)簽: Android
相關(guān)文章:
主站蜘蛛池模板: 成人片网址 | 免费在线日韩 | 网爆门在线 | 艳女av| 中文字幕在线免费 | 伊人网在线免费观看 | 日韩免费在线视频观看 | 毛片天堂| 亚洲美女在线播放 | 欧美视频黄 | 国产视频一区在线播放 | www.日韩高清 | 欧美激情视频在线 | 亚洲男人皇宫 | 四虎久久久| 欧美日韩免费做爰视频 | 日韩欧美中文 | 日韩黄色高清视频 | 黄色大片一级片 | 成人网址在线观看 | 中文字幕自拍偷拍 | 国产成人精品一区二区三区在线 | 欧美 日韩 中文 | 丁香六月婷婷激情 | 草草影院欧美 | 欧美日韩久久 | 午夜av免费在线观看 | 看全色黄大色黄女片18 | av一区二区三区四区 | 久久国产露脸精品国产 | 色综合国产 | 日韩一级免费毛片 | 在线观看视频h | 欧美综合一区 | 精品美女视频在线观看免费软件 | 中文字幕在线观看日韩 | 日韩精品久久久久久免费 | 99热这里只有精品99 | 国产美女久久久 | 青青草视频免费 | 小视频在线免费观看 |