J
J
Julia2015-08-12 14:18:35
Android
Julia, 2015-08-12 14:18:35

How to dynamically change the size of a fragment from a WebView on clicking a button inside a WebView?

We have a fragment inside which the WebView lives:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Context context=getActivity().getApplicationContext();
        myFrameLayout=new FrameLayout(context);
        viewer =new WebView(context);
        viewer.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        myFrameLayout.addView(viewer);
        return myFrameLayout;
    }

We populate the fragment in the activity, display it, catch the JS command that is triggered when you click on any object inside the WebView, which should expand, resize the fragment to full screen, the fragment in the markup has the wrap_content property. How to implement it dynamically? In general, is it reasonable to use a fragment, or is it better to draw your own view and populate the WebView in it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2015-08-12
@YushkaD

developer.android.com/reference/android/webkit/Web...
The addJavascriptInterface() method is what you need. There you can implement any logic.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question