日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android游戏开发系统控件-Dialog

發布時間:2023/12/10 Android 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android游戏开发系统控件-Dialog 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Android游戲開發系統控件-Dialog

Dialog(對話框)在Android應用開發中經常用到,下面是學習《Android游戲編程從零開始》一書,關于Dialog的初步學習。

創建項目:DialogProject

作者:wwj

日期:2012/5/13

功能:顯示有TextView和按鈕的對話框

?

簡單對話框:

添加單選框的對話框:

添加多選框的對話框:

添加列表的對話框:

?

添加自定義布局的對話框:

?

項目源代碼:

=>>main.xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" ><TextViewandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/hello" /></LinearLayout>


?

?

=>>dialogmain.xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_height="wrap_content"android:layout_width="wrap_content"android:background="#ffffffff" android:orientation="horizontal"android:id="@+id/myLayout"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="TextView"/><EditText android:layout_width="wrap_content"android:layout_height="wrap_content"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="btn1"/><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="btn2"/> </LinearLayout>


?

?

=>>DialogProjectActivity.java

package com.dialog;import android.app.Activity; import android.app.AlertDialog.Builder; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup;public class DialogProjectActivity extends Activity {private Builder builder; //聲明Bulider對象/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);//實例化Builder對象builder = new Builder(DialogProjectActivity.this);//設置對話框的圖標builder.setIcon(android.R.drawable.ic_dialog_info);//設置對話框的標題builder.setTitle("Dialog");//設置對話框提示文本// builder.setMessage("Dialog對話框");//監聽左側按鈕builder.setPositiveButton("Yes", new OnClickListener(){public void onClick(DialogInterface dialog,int which){}});//監聽右側按鈕builder.setNegativeButton("No",new OnClickListener(){public void onClick(DialogInterface dialog,int which){}});/*//添加單選按鈕builder.setSingleChoiceItems(new String[]{"單選","單選"},1,newOnClickListener(){public void onClick(DialogInterface dialog,int which){//which:選中下標}});//添加復選框builder.setMultiChoiceItems(new String[]{"多選","多選"},new boolean[]{false, true},new OnMultiChoiceClickListener(){public void onClick(DialogInterface dialog,int which,boolean isChecked){//which:選中下標//isChecked:選中項的勾選狀態}});//添加列表項builder.setItems(new String[]{"列表項1","列表項2","列表項3"},new OnClickListener(){public void onClick(DialogInterface dialog,int which){//which:選中下標項}});*///實例layout布局LayoutInflater inflater = getLayoutInflater();View layout = inflater.inflate(R.layout.dialogmain, (ViewGroup)findViewById(R.id.myLayout));builder.setView(layout);//調用show()方法顯示對話框builder.show();} }


?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

轉載于:https://www.cnblogs.com/wwj9413/archive/2012/05/13/2638587.html

總結

以上是生活随笔為你收集整理的Android游戏开发系统控件-Dialog的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。