如何在我所有的Andr​​oid应用程序中使用自定义对话框 [英] How to use a custom dialog in all of my application in android

查看:103
本文介绍了如何在我所有的Andr​​oid应用程序中使用自定义对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对话,我有很多的活动......我需要调用同一dailog的所有活动......目前,我已经写了code在每一个活动的,但这不是正确的方法......任何一个可以帮我在这

I have a dialog and i have many activities... I need to call the same dailog in all the activities...currently i have written the code in each of the activity but this is not the right way... Can any one help me in this

推荐答案

好吧下面是我在实现一个静态类对话框它,所以我可以从任何活动调用它,当我需要的方式

Ok below is my way of implementing dialog its in a static class so I can call it from any activity when I need

public static void showProgressDialog(Context mContext, String text, boolean cancellable)
{
    removeDialog();
    mDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
    mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

    LayoutInflater mInflater = LayoutInflater.from(mContext);
    View layout = mInflater.inflate(R.layout.popup_example, null);
    mDialog.setContentView(layout);

    TextView mTextView = (TextView) layout.findViewById(R.id.text);
    if (text.equals(""))
        mTextView.setVisibility(View.GONE);
    else
        mTextView.setText(text);

    mDialog.setOnKeyListener(new DialogInterface.OnKeyListener()
    {
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event)
        {
            switch (keyCode)
            {
            case KeyEvent.KEYCODE_BACK:
                return true;
            case KeyEvent.KEYCODE_SEARCH:
                return true;
            }
            return false;

        }
    });

    mDialog.setCancelable(cancellable);

    mDialog.show();
}

public static void removeDialog()
{
    if (mDialog != null)
        mDialog.dismiss();
}

这篇关于如何在我所有的Andr​​oid应用程序中使用自定义对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆