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

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

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

瀏覽:155日期: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ì)話(huà)框標(biāo)題 .setMessage('是否需要更換xxx?') .setPositiveButton('是', new DialogInterface.OnClickListener() {//添加確定按鈕 @Override public void onClick(DialogInterface dialog, int which) {//確定按鈕的響應(yīng)事件,點(diǎn)擊事件沒(méi)寫(xiě),自己添加 } }).setNegativeButton('否', new DialogInterface.OnClickListener() {//添加返回按鈕 @Override public void onClick(DialogInterface dialog, int which) {//響應(yīng)事件,點(diǎn)擊事件沒(méi)寫(xiě),自己添加 } }).show();//在按鍵響應(yīng)事件中顯示此對(duì)話(huà)框 } });

實(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ì)話(huà)框標(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ì)話(huà)框 } }); }}

<?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)文章:
主站蜘蛛池模板: 99热热热热 | 97爱爱爱 | 亚洲tv在线 | 亚洲午夜精品久久久久久浪潮 | 福利一区在线 | 麻豆国产视频 | 亚洲香蕉网站 | 免费毛片视频 | 欧美成人亚洲 | 天堂网免费视频 | 色屁屁ts人妖系列二区 | 国产精品久久毛片 | 中文字幕久久精品 | 国产精品观看 | 99国产精品久久久 | 成人极品视频 | 在线观看国产精品视频 | 99热这里都是精品 | 在线观看中文字幕一区 | 91精品在线观看视频 | 精品国产97 | 99在线观看 | 人人澡人人澡人人澡 | 欧美在线视频一区二区 | 99精品国产一区二区 | 免费久久精品 | 日本午夜激情 | a在线视频| 91亚洲国产成人精品一区二区三 | 中文不卡视频 | 欧美日韩国产在线 | 欧美在线观看视频一区 | 超碰不卡| 国产在线成人 | 男人天堂手机在线 | 糖心vlog免费在线观看 | 久久99久久99| 欧美黑人性猛交xxx 国产婷婷一区二区 | 四季av一区二区凹凸精品 | 成人免费在线 | 国产天堂在线观看 |