service是没有界面的,所以再service中加入的对话框是浮在activity'界面上的,这里的对话框会比较特殊一点 ,需要加一个属性:
mUpdateDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
还需要在manifest中添加一个权限:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
自定义dialog的代码如下:
View v = LayoutInflater.from(mContext).inflate(R.layout.update_version_dialog, null);
if (null == mUpdateDialog) {
if (null == v) {
return;
}
v.findViewById(R.id.group_item_recover_ok).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
v.findViewById(R.id.group_item_recover_cancle).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mUpdateDialog.dismiss();
mUpdateDialog=null;
}
});
// mUpdateDialog = new Dialog(mContext,android.R.style.Theme_Holo_Dialog_NoActionBar);
mUpdateDialog = new Dialog(GetSdCardAndUsbDataService.this,android.R.style.Theme_Holo_Dialog_NoActionBar);
LayoutParams lp=new LayoutParams(530, LayoutParams.WRAP_CONTENT);
mUpdateDialog.setContentView(v,lp);
Log.d(TAG, "Dialog setView success ");
}
if(null!=mUpdateDialog){
Log.d(TAG, "null !=Dialog ");
/*if (null != parent) {
parent.removeAllViews();
}*/
mUpdateDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
mUpdateDialog.show();
Log.d(TAG, "Dialog show success ");
}