Android WebView交互

	public class Fragment_Three extends Fragment {
	    private Button but;
	    private WebView web;
	    @Nullable
	    @Override
	    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
	        View view = inflater.inflate(R.layout.fragment_three, container, false);
	        but = view.findViewById(R.id.but);
	        web = view.findViewById(R.id.web);
	        return view;
	    }
	    @Override
	    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
	        super.onActivityCreated(savedInstanceState);
	        web.getSettings().setJavaScriptEnabled(true);
	        web.setWebChromeClient(new WebChromeClient());
	        web.loadUrl("file:///android_asset/index");
	        but.setOnClickListener(new View.OnClickListener() {
	            @Override
	            public void onClick(View v) {
	                web.post(new Runnable() {
	                    @Override
	                    public void run() {
	                        web.loadUrl("javascript:callJS()");
	                    }
	                });
	
	            }
	        });
	    }
	}

html


这里是标题

弹窗
替换标题
替换标题

你可能感兴趣的:(Android WebView交互)