尽管活动在后台进行并且新活动回来,但始终将Android弹出式窗口保持在最前端
问题描述:
这是一个弹出式窗口,正在活动A中显示。用户在活动A上按下按钮,然后活动B在顶部。但问题是,弹出还要落后活性B.尽管活动在后台进行并且新活动回来,但始终将Android弹出式窗口保持在最前端
我想弹出来始终在最前面,即使活动回地面进入
LayoutInflater layoutInflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
LeadOffPopView = layoutInflater.inflate(
R.layout.leadoffdetect, null);
LeadOffPopWindow = new PopupWindow(
LeadOffPopView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
final TextView bLATxtVw = (TextView) (LeadOffPopView)
.findViewById(R.id.LATxtVw);
final TextView bRATextView = (TextView) (LeadOffPopView)
.findViewById(R.id.RATxtVw);
final TextView bLLTextView = (TextView) (LeadOffPopView)
.findViewById(R.id.LLTxtVw);
final TextView bRLTextView = (TextView) (LeadOffPopView)
.findViewById(R.id.RLTxtVw);
final TextView bV1TextView = (TextView) (LeadOffPopView)
.findViewById(R.id.V1TxtVw);
final TextView bV2TextView = (TextView) (LeadOffPopView)
.findViewById(R.id.V2TxtVw);
final TextView bV3TextView = (TextView) (LeadOffPopView)
.findViewById(R.id.V3TxtVw);
final TextView bV4TextView = (TextView) (LeadOffPopView)
.findViewById(R.id.V4TxtVw);
final TextView bV5TextView = (TextView) (LeadOffPopView)
.findViewById(R.id.V5TxtVw);
final TextView bV6TextView = (TextView) (LeadOffPopView)
.findViewById(R.id.V6TxtVw);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (bLAOff) {
bLATxtVw.setVisibility(View.VISIBLE);
} else
bRATextView
.setVisibility(View.INVISIBLE);
if (bRAOff) {
bRATextView
.setVisibility(View.VISIBLE);
} else
bRATextView
.setVisibility(View.INVISIBLE);
if (bLLOff) {
bLLTextView
.setVisibility(View.VISIBLE);
} else
bLLTextView
.setVisibility(View.INVISIBLE);
if (bRLOff) {
bRLTextView
.setVisibility(View.VISIBLE);
} else
bRLTextView
.setVisibility(View.INVISIBLE);
if (bV1Off) {
if(!MainClass.bLANDSCAPEENABLED)
bV1TextView
.setVisibility(View.VISIBLE);
} else
bV1TextView
.setVisibility(View.INVISIBLE);
if (bV2Off) {
if(!MainClass.bLANDSCAPEENABLED)
bV2TextView
.setVisibility(View.VISIBLE);
} else
bV2TextView
.setVisibility(View.INVISIBLE);
if (bV3Off) {
if(!MainClass.bLANDSCAPEENABLED)
bV3TextView
.setVisibility(View.VISIBLE);
} else
bV3TextView
.setVisibility(View.INVISIBLE);
if (bV4Off) {
if(!MainClass.bLANDSCAPEENABLED)
bV4TextView
.setVisibility(View.VISIBLE);
} else
bV4TextView
.setVisibility(View.INVISIBLE);
if (bV5Off) {
if(!MainClass.bLANDSCAPEENABLED)
bV5TextView
.setVisibility(View.VISIBLE);
} else
bV5TextView
.setVisibility(View.INVISIBLE);
if (bV6Off) {
if(!MainClass.bLANDSCAPEENABLED)
bV6TextView
.setVisibility(View.VISIBLE);
} else
bV6TextView
.setVisibility(View.INVISIBLE);
handler.postDelayed(this, 500);
}
}, 250);
LeadOffPopWindow.showAtLocation(
LeadOffPopView,
Gravity.CENTER_HORIZONTAL | Gravity.TOP,20 ,
300);
答
PopUpWindow /对话框连接你的活动窗口管理范围内,所以当你的活动将在后台进行,PopUpWindow/Dialog也将隐藏。
因此请使用系统警报PopupWindow /对话框为达到这个目的,你可以使用下面的代码创建系统对话框:
AlertDialog newDialog = new AlertDialog.Builder(context)
.setMessage(text)
.setPositiveButton(R.string.ok, null)
.setCancelable(true)
.create();
newDialog.getWindow().setType(
WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);
newDialog.getWindow().addFlags(
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
newDialog.show();