码迷,mamicode.com
首页 > 其他好文 > 详细

官方关于Dialog的介绍

时间:2014-05-10 07:52:33      阅读:369      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   class   code   java   

将Activity显示成Dialog的形式:

Tip: If you want a custom dialog, you can instead display an Activity as a dialog instead of using the Dialog APIs. Simply create an activity and set its theme to Theme.Holo.Dialog in the <activity> manifest element:

<activityandroid:theme="@android:style/Theme.Holo.Dialog">

That‘s it. The activity now displays in a dialog window instead of fullscreen.

 

将dialog的按钮点击事件传递给Activity:

  

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package leihu.dialogtoactivity;
 
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
 
@SuppressLint("NewApi")
public class NoticeDialogFragment extends DialogFragment{
     
    public interface NoticeDialogListener{
        public void onDialogPositiveClick(DialogFragment dialog);
        @SuppressLint("NewApi")
        public void onDialogNegativeClick(DialogFragment dialog);
    }
     
    NoticeDialogListener mListener;
 
    @SuppressLint("NewApi")
    @Override
    public void onAttach(Activity activity) {    //Called when a fragment is first attached to its activity                                                     //<code><a href="http://i.cnblogs.com/reference/android/app/Fragment.html#onCreate(android.os.Bundle)">onCreate(Bundle)</a></code> will be called after this.
        super.onAttach(activity);
        try {
            mListener = (NoticeDialogListener) activity;
        } catch (Exception e) {
            throw new ClassCastException(activity.toString()
                    + " must implement NoticeDialogListener");
        }
    }
 
    @SuppressLint("NewApi")
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setMessage("fire missiles")
            .setPositiveButton("frie", new DialogInterface.OnClickListener() {
                 
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    mListener.onDialogPositiveClick(NoticeDialogFragment.this);
                }
            })
             .setNegativeButton("cancel", new DialogInterface.OnClickListener() {
                 
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    mListener.onDialogNegativeClick(NoticeDialogFragment.this);
                }
            });
        return builder.create();
    }
     
     
     
     
}

  

官方关于Dialog的介绍,布布扣,bubuko.com

官方关于Dialog的介绍

标签:android   style   blog   class   code   java   

原文地址:http://www.cnblogs.com/leihupqrst/p/3718964.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!