Javascript Android材质选项卡栏和webview
我在网上找到了这个项目: 这是android在材料设计中的一个模板,我想在每个选项卡栏中添加不同的web视图,当我尝试添加时,它会给我带来很多语法错误。 代码如下:Javascript Android材质选项卡栏和webview,javascript,android,eclipse,android-fragments,android-studio,Javascript,Android,Eclipse,Android Fragments,Android Studio,我在网上找到了这个项目: 这是android在材料设计中的一个模板,我想在每个选项卡栏中添加不同的web视图,当我尝试添加时,它会给我带来很多语法错误。 代码如下: public class SampleFragment extends Fragment { private static final String ARG_POSITION = "position"; private WebView myWebView; private String LOG_TAG =
public class SampleFragment extends Fragment {
private static final String ARG_POSITION = "position";
private WebView myWebView;
private String LOG_TAG = "AndroidWebViewActivity";
private int position;
public static SampleFragment newInstance(int position) {
SampleFragment f = new SampleFragment();
Bundle b = new Bundle();
b.putInt(ARG_POSITION, position);
f.setArguments(b);
return f;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
position = getArguments().getInt(ARG_POSITION);
View rootView = inflater.inflate(R.layout.page, container, false);
ProgressBarCircular progressBarCircular = (ProgressBarCircular) rootView.findViewById(R.id.progress);
FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fabButton);
fab.setDrawableIcon(getResources().getDrawable(R.drawable.plus));
switch (position) {
case 0:
myWebView = (WebView) findViewById(R.id.webView);
//enable Javascript
myWebView.getSettings().setJavaScriptEnabled(true);
//loads the WebView completely zoomed out
myWebView.getSettings().setLoadWithOverviewMode(true);
//true makes the Webview have a normal viewport such as a normal desktop browser
//when false the webview will have a viewport constrained to it's own dimensions
myWebView.getSettings().setUseWideViewPort(true);
//override the web client to open all links in the same webview
myWebView.setWebViewClient(new MyWebViewClient());
myWebView.setWebChromeClient(new MyWebChromeClient());
//Injects the supplied Java object into this WebView. The object is injected into the
//JavaScript context of the main frame, using the supplied name. This allows the
//Java object's public methods to be accessed from JavaScript.
myWebView.addJavascriptInterface(new JavaScriptInterface(this), "Android");
//load the home page URL
myWebView.loadUrl("http://demo.mysamplecode.com/Servlets_JSP/pages/androidWebView.jsp");
break;
case 1:
break;
case 2:
break;
case 3:
break;
}
return rootView;
}
}
我想说:
myWebView = (WebView) findViewById(R.id.webView);
//enable Javascript
myWebView.getSettings().setJavaScriptEnabled(true);
//loads the WebView completely zoomed out
myWebView.getSettings().setLoadWithOverviewMode(true);
//true makes the Webview have a normal viewport such as a normal desktop browser
//when false the webview will have a viewport constrained to it's own dimensions
myWebView.getSettings().setUseWideViewPort(true);
//override the web client to open all links in the same webview
myWebView.setWebViewClient(new MyWebViewClient());
myWebView.setWebChromeClient(new MyWebChromeClient());
//Injects the supplied Java object into this WebView. The object is injected into the
//JavaScript context of the main frame, using the supplied name. This allows the
//Java object's public methods to be accessed from JavaScript.
myWebView.addJavascriptInterface(new JavaScriptInterface(this), "Android");
//load the home page URL
myWebView.loadUrl("http://demo.mysamplecode.com/Servlets_JSP/pages/androidWebView.jsp");
在每个“案例”中,更改url
但这是我得到的错误:
错误:(33,10)找不到符号方法
setArguments(android.os.Bundle)错误:(39,20)找不到符号
方法getArguments()错误:(63,48)找不到符号类
MyWebViewClient错误:(64,50)找不到符号类
MyWebChromeClient错误:(69,54)找不到符号类
JavaScriptInterface
您是否创建了MyWebViewClient和MyWebChromeClient类?