【发布时间】:2016-05-08 20:46:19
【问题描述】:
我创建了应用程序,但在 Fragment 中使用带有外部链接的 WebView 时遇到问题。
我有 webView_layout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="by.beep.materialvebweiv.activity.FriendsFragment">
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/webView" />
</RelativeLayout>
类
package by.beep.materialvebweiv.activity;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import by.beep.materialvebweiv.R;
public class FriendsFragment extends Fragment {
public FriendsFragment() {
}
public WebView mWebView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v=inflater.inflate(R.layout.fragment_friends, container, false);
mWebView = (WebView) v.findViewById(R.id.webView);
mWebView.loadUrl("https://google.com");
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient());
return v;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
}
@Override
public void onDetach() {
super.onDetach();
}
}
我尝试在 Fragment 中使用 WebView 与下一个案例:如果 URL 不包含“google.com”重定向以在默认浏览器中打开链接。
谁能帮帮我?
【问题讨论】:
标签: android android-fragments webview