提醒对话框:
布局文件:alertdialog.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="150dip"
android:padding="10dip"
android:background="@color/dialog_bg"
>
<LinearLayout android:id="@+id/title_layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<TextView android:id="@+id/title_text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:text="备份提醒"
android:textColor="#FFF"/>
</LinearLayout>
<LinearLayout android:id="@+id/bottom_layout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button android:id="@+id/button_yes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=" 是 "
android:gravity="center" />
<Button android:id="@+id/button_no"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=" 否 "
android:gravity="center" />
</LinearLayout>
</RelativeLayout>
自定义类AlertDialog.java
public class AlertDialog extends Dialog implements android.view.View.OnClickListener
{
OnClickListener onClickListener;
Button yes;
Button no;
public AlertDialog(Context context)
{
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getWindow().findViewById(android.R.id.title).setVisibility(View.GONE);//隐藏对话框的标题
//getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.alertdialog);
yes = (Button)findViewById(R.id.button_yes);
no = (Button)findViewById(R.id.button_no);
yes.setOnClickListener(this);
no.setOnClickListener(this);
}
@Override
protected void onStop()
{
// TODO Auto-generated method stub
super.onStop();
}
@Override
public void onClick(View v)
{
switch(v.getId()) {
case R.id.button_yes:
onClickListener.onClick(onClickListener.BUTTON_YES);
break;
case R.id.button_no:
onClickListener.onClick(onClickListener.BUTTON_NO);
break;
}
}
public void setOnClickListener(OnClickListener onClickListener)
{
this.onClickListener = onClickListener;
}
public interface OnClickListener {
public static final int BUTTON_YES = 0;
public static final int BUTTON_NO = 1;
void onClick(int type);
}
}
调用代码:
protected Dialog onCreateDialog(int id)
{
switch(id) {
case ALERT_DIALOG:
AlertDialog dialog = new AlertDialog(ContactsActivity.this);
dialog.setOnClickListener(new AlertDialog.OnClickListener()
{
@Override
public void onClick(int type)
{
switch(type) {
case AlertDialog.OnClickListener.BUTTON_YES:
dismissDialog(ALERT_DIALOG);
//showDialog(PROGRESS_DIALOG);
backupContacts();
break;
case AlertDialog.OnClickListener.BUTTON_NO:
dismissDialog(ALERT_DIALOG);
break;
}
}
});
dialog.setCancelable(false);//按back键不关闭对话框
return dialog;
case PROGRESS_DIALOG:
}
return super.onCreateDialog(id);
}
分享到:
相关推荐
Android自定义对话框Dialog(界面美化)
创建自定义对话框dialog,弹出模式窗口 用于创建自定义对话框的轻量级(约 4.5 KB)代码库。四种对话框可用: alerts(出错), warnings(警告), prompts(提示), success(成功)。利用一个简单的函数,你可以自定义对话框...
Android自定义对话框Dialog(界面美化).zip
qml 用item自定义dialog 对话框 很好用的一个自定义对话框
本文简单介绍自定义对话框Dialog的使用,代码和结构都非常简单,目的是能够快速使用自定义对话框,在本文中不具体讲解对话框的高级使用。 实现步骤 首先需要自己在我们的.xml文件中自己构建布局 布局文件做好之后,...
自定义对话框自定义对话框自定义对话框自定义对话框自定义对话框
WPF 自定义对话框,修正完美版,下载可以用,可以自定义样式
本文实例讲述了Android编程实现在自定义对话框中获取EditText中数据的方法。分享给大家供大家参考,具体如下: 在项目中忽然遇到这样的问题,需要自定义对话框,对话框需要有一个输入框,以便修改所选中的价格,然后...
android自定义对话框、dianlog;详细讲解请参考:http://blog.csdn.net/tangron/article/details/19474385
安卓常用自定义动画效果对话框,包括确认,取消,删除等多种效果!
主要为大家详细介绍了Android自定义对话框Dialog的简单实现,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
自定义对话框LoadingDialog和Toast,可以添加Gif动画的Dialog,喜欢的自行下载!
Dialog对话框之android 自定义对话框代码 设置对话框显示一个单选的List 用来设置对话框显示一系列的复选框 设置进度条风格,风格为圆形,旋转的
在swing实际开发中,使用自定义对话框是非常有用的。 该例子是翻写sun JDK中CustomDialog.java和DialogDemo.java
该源码实现了自定义对话框Dialog效果源码,该项目实现了自定义对话框,自定义消息提示框,可以通过点击屏幕中央的“点击测试”,系统会弹出一个漂亮的消息提示框,分别实现了“确定”、“取消”按钮的接口事件,也是...
一般自定义对话框有三种办法: 1、重写Dialog来实现。 2、获取Dialog的Window对象实现。 3、使用WindowManager来实现。 4、使用DialogTheme来实现。 详细请看:...
dialogfragment自定义对话框使用实例.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
主要介绍了Androd自定义对话框Dialog视图及参数传递的实现方法,非常不错,具有参考借鉴价值,需要的朋友可以参考下