Android入门--弹出三个按钮的对话框
来源:互联网 发布:阿里云os系统的手机 编辑:程序博客网 时间:2024/06/06 19:04
在GUI程序中,有时需要弹出对话框来提示一些信息。
这些对话框比一个独立的屏幕简单,在Android中弹出式对话框不同于表示一个屏幕的活动,它通常用于简单的功能处理。
对话框的父类是android.app.Dialog,通过构建类android.app.AlertDialog来实现弹出式对话框,可以使用AlertDialog.Builder和不同的参数来构建对话框。
效果如下图所示:
activity_forwarding.xml代码如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.forwarding.Forwarding" > <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:text="@string/Btn01" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/button1" android:layout_marginTop="20dp" android:text="@string/Texts" android:textAppearance="?android:attr/textAppearanceLarge" /> </RelativeLayout>
Forwarding.java代码如下:
package com.example.forwarding;import android.support.v7.app.ActionBarActivity;import android.app.AlertDialog;import android.content.DialogInterface;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.TextView;public class Forwarding extends ActionBarActivity {@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_forwarding);final Button dialogButton = (Button) findViewById(R.id.button1);final TextView texts = (TextView) findViewById(R.id.textView1);dialogButton.setOnClickListener(new View.OnClickListener() {// 按键单击事件@Overridepublic void onClick(View v) {// TODO Auto-generated method stubnew AlertDialog.Builder(Forwarding.this).setTitle("系统提示")// 设置对话框标题.setMessage("请确认所有数据都保存后再推出系统!")// 设置显示的内容//右边按钮.setPositiveButton("确定",new DialogInterface.OnClickListener() {// 添加确定按钮@Overridepublic void onClick(DialogInterface dialog,int which) {// 确定按钮的响应事件// TODO Auto-generated method// stub//finish();texts.setText("结果:确认 ");}})//中间按钮.setNeutralButton("测试", new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int whichButton) {texts.setText("结果:测试 ");}})//左边按钮.setNegativeButton("返回",new DialogInterface.OnClickListener() {// 添加返回按钮@Overridepublic void onClick(DialogInterface dialog,int which) {// 响应事件// TODO Auto-generated method// stub//Log.i("alertdialog", " 请保存数据!");texts.setText("结果:返回 ");}}).show();// 在按键响应事件中显示此对话框}});}}
1 0
- Android入门--弹出三个按钮的对话框
- Android 三个按钮对话框
- android自定义三个按钮的dialog对话框
- Android点击按钮弹出对话框
- android开发 点击按钮弹出对话框的简单实现
- Android 点击一个按钮,弹出一个对话框
- Android 点击按钮弹出ListView对话框
- 点击按钮后弹出新的对话框
- Button按钮的使用和弹出对话框
- 点击按钮弹出对话框
- 点击按钮弹出对话框
- MFC 按钮弹出对话框
- 点击按钮,弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- X86架构小机以何应对核心业务
- 两次返回退出进程同时杀死进程
- javascript中的try catch异常捕获机制
- windows缺少网络协议,网络连接失败
- Java-对称加密-AES
- Android入门--弹出三个按钮的对话框
- 最少拦截系统
- 一念永恒 > 第七十八章 他们是在说我么
- 【颗粒归仓】(四)代码走查--StyleCop所有规范的翻译准则
- JetBrains公司系列IDE开发工具通用初始配置推荐(Android Studio、InterlliJ、PHPStorm、CLion、Webstorm等)
- 一念永恒 > 第七十七章 拍卖会
- Androidstudio真机调试出现的问题
- .NET平台构造块(CLR、CTS和CLS)及基础类库
- VMware用技术浇灌生态之花