问题解决了:只需在提交片段之前添加“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; }解决方法 将片段附加到Activity时,必须使用FragmentTransaction.addToBackStack方法.这是文档中的引用
总结Add this transaction to the back stack. This means that the transaction will be remembered after it is committed,and will reverse its operation when later popped off the stack.
以上是内存溢出为你收集整理的android – 应用程序在Fragment中单击后退按钮后关闭全部内容,希望文章能够帮你解决android – 应用程序在Fragment中单击后退按钮后关闭所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)