MuPDF for Android: Option for fragment instead Activity

前端 未结 2 1481
深忆病人
深忆病人 2021-01-05 17:38

In my existing android app, Im using MuPDF, which i ported with help of this doc. Now when i want to open pdf files inside activity i use : Uri uri = Uri.parse(path);

<
2条回答
  •  说谎
    说谎 (楼主)
    2021-01-05 18:09

    Maybe you shouldn't use the MuPDFActivity in your project - it's just an example how Mupdf works. All what you need is the MuPDFReaderView/MuPDFCore/MuPDFPageAdapter. MuPDFReaderView extends from View/ViewGroup, so you can just add it to your layout. Try it like this (totally untested!!):

    1.) XML --> The base layout for the fragment (mupdf_wrapper.xml):

    
    
    

    2.) JAVA:

    public class DummySectionFragment extends Fragment {
    
        public DummySectionFragment() {
        }
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    
            View  rootView = null;
    
            rootView = inflater.inflate(R.layout.mupdf_wrapper, container, false);
            RelativeLayout mupdfWrapper (RelativeLayout)rootView.findViewById(R.id.mupdf_wrapper);
            String path = "path/To/Your/PDF/File.pdf";
            MuPDFCore core = new MuPDFCore(getActivity(), path);
            MuPDFReaderView mDocView = new MuPDFReaderView(getActivity());
            mDocView.setAdapter(new MuPDFPageAdapter(getActivity(), getActivity(), core));
            mupdfWrapper .addView(mDocView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            return rootView;
        }
    

    }

提交回复
热议问题