我有一个PopupWindow,我希望它在用户触摸外面时解散,所以我调查并发现我必须使用它popup.setBackgroundDrawable(new BitmapDrawable());.问题new BitmpaDrawable()是不推荐使用构造函数.我想在不使用它的情况下找到解决方案.
谁知道怎么解决这个问题?
谢谢!
final PopupWindow popup = new PopupWindow(sortByView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
true);
popup.setBackgroundDrawable(new BitmapDrawable());
popup.setOutsideTouchable(true);
popup.showAsDropDown(v);
Run Code Online (Sandbox Code Playgroud) 所以,我的程序运行正常.我只留下三个警告(每个弹出窗口一个),它让我很烦恼,我一直在寻找一个能满足我需求的解决方案,但我似乎无法找到一个.
这是我的代码(其他两个popupwindows相似)
else if(id == R.id.action_resetstats){
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.resetpop, null);
final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
Button yesDismiss = (Button)popupView.findViewById(R.id.yesDismiss);
yesDismiss.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v){
SharedPreferences prefs = getSharedPreferences(savedData, Context.MODE_PRIVATE);
Editor editor = prefs.edit();
editor.clear();
editor.commit();
counterW = 0;
counterL = 0;
counterT = 0;
counterTot = 0;
timerTime = 3;
popupWindow.dismiss();
}
});
popupWindow.showAsDropDown(yeDismiss, 50, 50);
Button noDismiss = (Button)popupView.findViewById(R.id.noDismiss);
noDismiss.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v){
popupWindow.dismiss();
}
});
popupWindow.showAsDropDown(naDismiss, …Run Code Online (Sandbox Code Playgroud)