日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

安卓飞机大战(三) 弹出对话框

發(fā)布時(shí)間:2025/3/20 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 安卓飞机大战(三) 弹出对话框 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

在游戲時(shí),不管是退出游戲還是選擇戰(zhàn)機(jī),都要彈出一個(gè)對(duì)話框,需要以下代碼


按一個(gè)按鈕彈出對(duì)話框


Layout文件:(添加一個(gè)按鈕)

<Button
??????? android:id="@+id/button1"
??????? android:layout_width="fill_parent"
??????? android:layout_height="wrap_content"
??????? android:text="準(zhǔn)備起飛" />



在MainActivity 中:


public class choiceActivity extends Activity {
?? ?private Button button1;
?? ?protected void onCreate(Bundle savedInstanceState) {
??????? super.onCreate(savedInstanceState);
??????? setContentView(R.layout.choice);
??????? button1=(ImageButton)findViewById(R.id.p_w_picpathButton1);
??????? button2=(ImageButton)findViewById(R.id.p_w_picpathButton2);
??????? button1.setOnClickListener(new View.OnClickListener() {
?? ??? ??? ?
?? ??? ??? ?@Override
?? ??? ??? ?public void onClick(View arg0) {
?? ??? ??? ??? ?AlertDialog.Builder builder = new AlertDialog.Builder(choiceActivity.this);
??????????????? //??? 設(shè)置Title的圖標(biāo)
??????????????? builder.setIcon(R.drawable.ic_yxlm);
??????????????? //??? 設(shè)置Title的內(nèi)容
??????????????? builder.setTitle("進(jìn)入游戲");
??????????????? //??? 設(shè)置Content來顯示一個(gè)信息
??????????????? builder.setMessage("確定選擇進(jìn)入游戲嗎?");
??????????????? //??? 設(shè)置一個(gè)PositiveButton
??????????????? builder.setPositiveButton("確定", new DialogInterface.OnClickListener()
??????????????? {
??????????????????? @Override
??????????????????? public void onClick(DialogInterface dialog, int which)
??????????????????? {
??????????????????????? Toast.makeText(choiceActivity.this, "進(jìn)入游戲 ", Toast.LENGTH_SHORT).show();
??????????????????????? Intent intent=new Intent(choiceActivity.this,userActivity.class);
?????? ??? ??? ??? ??? ?startActivity(intent);//跳轉(zhuǎn)到下一個(gè)界面userActivity

??????????????????????? finish();
??????????????????? }
??????????????? });
??????????????? //??? 設(shè)置一個(gè)NegativeButton
??????????????? builder.setNegativeButton("取消", new DialogInterface.OnClickListener()
??????????????? {
??????????????????? @Override
??????????????????? public void onClick(DialogInterface dialog, int which)
??????????????????? {
??????????????????????? Toast.makeText(choiceActivity.this, "繼續(xù)選擇", Toast.LENGTH_SHORT).show();
??????????????????? }
??????????????? });
??????????????? builder.show();
?? ??? ??? ??? ?
?? ??? ??? ?}
?? ??? ?});

}




這樣就可以實(shí)現(xiàn)一個(gè)對(duì)話框了!

轉(zhuǎn)載于:https://blog.51cto.com/bigcrab/1685032

總結(jié)

以上是生活随笔為你收集整理的安卓飞机大战(三) 弹出对话框的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。