点击enter按钮会关闭对话框,留在当前Activity,点击exit按钮则退出应用。
首先是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:background="#FFFFFFFF"
- android:orientation="vertical" >
- <Button
- android:id="@+id/button"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/hello" />
- </LinearLayout>
主Activity代码CustomAlertDialogActivity.java:
- package nbe.sense7.vinci.custom.alertdialog;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.Window;
- import android.widget.Button;
- import android.widget.ImageButton;
- public class CustomAlertDialogActivity extends Activity {
- /** Called when the activity is first created. */
- private Button button;
自定义对话框布局文件custom_alertdialog.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:layout_margin="15dp"
- android:gravity="center_horizontal"
- android:orientation="horizontal"
- android:background="@drawable/dialog_bg">
- <!-- enter button -->
- <ImageButton
- android:id="@+id/enter_btn"
- android:layout_height="wrap_content"
- android:layout_width="wrap_content"
文章链接: https://www.mfisp.com/24351.html
文章标题:AlertDialog自定义控件
文章版权:梦飞科技所发布的内容,部分为原创文章,转载请注明来源,网络转载文章如有侵权请联系我们!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。