Х ребят,onBackPressed не вызывается, когда PopupWindow показывает
Так в настоящее время я использую PopupWindow для отображения в приложении браузере. Однако при нажатии кнопки «Назад» он ничего не делает. Я использую PopupWindow в другом фрагменте, затем я использую оператор, чтобы установить PopupWindow в свой FragmentActivity, а затем, когда я нажимаю кнопку «назад», он должен проверить, установлен ли PopupWindow или нет, и отклонить его или нет. Однако он даже не запускается через onBackPressed.
PopupWindow в фрагменте:
-> где я указываю строку, которая удостоверяется FragmentActivity получает PopupWindow, а также.
// Use webview for icons and website link.
public void inAppBrowser(String url){
mCursor.moveToFirst();
// Inflate View
LayoutInflater layoutInflater = (LayoutInflater) ((MainActivity) MainActivity.getContext()).getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View inflatedView = layoutInflater.inflate(R.layout.browser_window, null, false);
// Control View Childs.
LinearLayout header = (LinearLayout) inflatedView.findViewById(R.id.filter_header);
header.setBackgroundColor(Color.parseColor(color));
Button cancel = (Button) inflatedView.findViewById(R.id.cancel);
Button done = (Button) inflatedView.findViewById(R.id.done);
// Set PopupWindow position.
Display display = ((MainActivity) MainActivity.getContext()).getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
// Control PopupWindow.
final PopupWindow popWindow = new PopupWindow(inflatedView, size.x, size.y, true);
popWindow.setAnimationStyle(android.R.anim.fade_in);
popWindow.setFocusable(true);
popWindow.setOutsideTouchable(true);
popWindow.showAtLocation(v, Gravity.BOTTOM, 0, 150);
--> MainActivity.setPopupWindow(popWindow);
// Control WebView
WebView myWebView = (WebView) inflatedView.findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClientAdapter());
myWebView.clearCache(true);
myWebView.clearHistory();
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
MainActivity.setWebView(myWebView);
if (url != null) {
if (url.contains("http://") || url.contains("https://")) {
} else {
url = "http://" + url;
}
myWebView.loadUrl(url);
} else {
popWindow.dismiss();
MainActivity.setPopupWindow(null);
MainActivity.setWebView(null);
}
cancel.setVisibility(View.INVISIBLE);
done.setText("Close");
done.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popWindow.dismiss();
}
});
}
Мой onBackPressed код:
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
//check if popupwindow is open
Log.e(TAG, "Check if it runs through this section");
if (popWindow != null) {
if (myWebView != null && myWebView.canGoBack()) {
myWebView.goBack();
} else {
popWindow.dismiss();
popWindow = null;
myWebView = null;
}
}
}
Игнорируйте WebView на данный момент. Это может быть вопросом в будущем, но я хочу, чтобы PopupWindow закрылся первым. Любая помощь приветствуется.
Это сработало, спасибо! –
удивительный! u сохранить мой день –
Не работает на Android 4.4.2 с помощью 'new PopupWindows (Context); popupWindow.setFocusable (false); ' –