自定义dialog package com.zhiduan.crowdclient.view; import com.zhiduan.crowdclient.MyApplication; import com.zhiduan.crowdclient.R; import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.view.Display; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.view.WindowManager; import android.widget.Button; import android.widget.ImageView; /** * 单点登录提示窗口(该账号在另一设备登录) * * @author yxx * * @date 2016-5-3 下午10:00:31 * */ public class SingleLoginDialog{ public static boolean isShow = false; static Dialog dialog; // 弹窗结果回调函数 public static abstract class ResultCallback { public abstract void callback(boolean result); } public SingleLoginDialog(Context context){ } /** * @param context * @param strMessage */ public static void showMyDialog(Context context, final ResultCallback callback){ if(dialog != null){ dialog.dismiss(); } dialog = new Dialog(context, R.style.dialog); LayoutInflater inflater = dialog.getLayoutInflater(); View layout = inflater.inflate(R.layout.dialog_single_login, null); Button btnOK = (Button) layout.findViewById(R.id.btn_single_login_ok); ImageView img = (ImageView) layout.findViewById(R.id.p_w_picpathView1); btnOK.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { callback.callback(true); dialog.dismiss(); } }); img.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub dialog.dismiss(); } }); dialog.setContentView(layout); dialog.setCancelable(false); dialog.setCanceledOnTouchOutside(false); dialog.show(); setDialogWindowAttr(dialog, context); isShow = true; } /** * 关闭窗口 */ public static void closeDialog(){ SingleLoginDialog.isShow = false; if(dialog != null){ dialog.dismiss(); } } //在dialog.show()之后调用 public static void setDialogWindowAttr(Dialog dlg,Context ctx){ WindowManager wm = ((Activity) ctx).getWindowManager(); Display display = wm.getDefaultDisplay(); // 为获取屏幕宽、高 Window window = dlg.getWindow(); WindowManager.LayoutParams lp = window.getAttributes(); lp.gravity = Gravity.CENTER; lp.width = (int) (display.getWidth()/1.5); lp.height = (int) (display.getHeight()/3); dlg.getWindow().setAttributes(lp); } } styles.xml <style name="dialog" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowIsFloating">true</item> <item name="android:windowIsTranslucent">false</item> <item name="android:windowNoTitle">true</item> <item name="android:background">@android:color/transparent</item> <item name="android:windowBackground">@android:color/transparent</item> <!-- 隐藏标题栏 --> <item name="android:backgroundDimEnabled">true</item> <item name="android:backgroundDimAmount">0.6</item> <!-- 对话框外区域的灰度 --> </style>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。