私は同じ問題に直面していましたが、解決策
Android's official Documentation about WebViewを見つけました
これが私のonCreateView()
方法で、ここでは2つの方法を使用してURLを開きます。
方法1はブラウザで
URLを開き、
方法2は目的のWebViewでURLを開きます。
そして、私はアプリケーションに方法 2 を使用しています。これが私のコードです。
public class MainActivity extends Activity {
private WebView myWebView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_webpage_detail, container, false);
// Show the dummy content as text in a TextView.
if (mItem != null) {
/* Method : 1
This following line is working fine BUT when we click the menu item then it opens the URL in BROWSER not in WebView */
//((WebView) rootView.findViewById(R.id.detail_area)).loadUrl(mItem.url);
// Method : 2
myWebView = (WebView) rootView.findViewById(R.id.detail_area); // get your WebView form your xml file
myWebView.setWebViewClient(new WebViewClient()); // set the WebViewClient
myWebView.loadUrl(mItem.url); // Load your desired url
}
return rootView;
} }