android fragment 退出程序,android – 应用程序在Fragment中单击后退按钮后关闭
[UPDATE]
問題解決了:只需在提交片段之前添加“addToBackStack(null)”:
Fragment fragment = new WebBrowserFragment();
fragment.setArguments(arguments);
FragmentTransaction fragmentTransaction = getActivity().getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
這是我片段的代碼.當我在這個片段上并點擊后退按鈕時,我的應用程序將關閉.
我想回到之前加載的片段.
我該怎么做才能強迫這種行為?
public class WebBrowserFragment extends Fragment {
WebView mWebView;
ProgressBar progressB = null;
private String mUrl;
private static String mtitle;
private static String msource;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
LayoutInflater mInflater = (LayoutInflater) getActivity().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View view = (View) mInflater.inflate(R.layout.web_browser_view, null);
MainActivity.setShareButtonToVisible();
Bundle bundle = getArguments();
String url = bundle.getString("URL");
mtitle = bundle.getString("TITRE");
msource = bundle.getString("SOURCE");
mUrl = url;
progressB = (ProgressBar) view.findViewById(R.id.progressBar1);
mWebView = (WebView) view.findViewById(R.id.webViewArticle);
mWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
if(progress < 100 && progressB.getVisibility() == ProgressBar.GONE){
progressB.setVisibility(ProgressBar.VISIBLE);
}
progressB.setProgress(progress);
if(progress == 100) {
progressB.setVisibility(ProgressBar.GONE);
}
}
});
mWebView.loadUrl(url);
return view;
}
總結
以上是生活随笔為你收集整理的android fragment 退出程序,android – 应用程序在Fragment中单击后退按钮后关闭的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android调小边框距离,Recycl
- 下一篇: android 进lanucher的广播