does someone know how I can link between 2 WebView fragments? Both WebView fragments use local html sources. So I want to link to the other WebView Fragment via inline HTML href.
I think something like Intent or Fragment Interfaces could work here. But don´t know exactly how to access the href tag to native Android code.
If you see the picture above - the solution should be open Link WebView 1 and switch to the 2nd WebView. Its implemented with Bottom Navigation, so the first Tab (WebView) should switch over the second Tab (WebView) as it works nativly on tabbing the icons.
UPDATE
This new material design in Android is amazing. When i want to programatically switch the view - I don´t have to call the fragment transaction methods. I just have to do this:
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
and now the magic:
navigation.setSelectedItemId(R.id.navigation_myView);
This also sync the Bottom Navigation State and load the fragment view. In my case i call this within a JavaScript Bridge. Android rocks friends.
You need to look at the JavascriptInterface
annotation class. The JavascriptInterface
annocation gives you a way to call Android methods from javascript in your WebView
.
You can find a ton of tutorials out there, but the way it works basically is this:
Create a POJO with a method you would like to call from javascript in your WebView
. This method can have only String
type arguments.
Annotate the method with @JavascriptInterface annotation.
Call webView.addJavaScriptInterface(pojo, "js")
to inject your POJO into the WebView
. (The String tag is arbitrary.)
In your javascript, call js.yourMethod()
to invoke the method on your POJO.
So in your case, when someone clicks the button in webview1, you call an Android method through the javascript interface to display webview2.