android material tab,javascript - Android material tab bar and webview - Stack Overflow

It's a template for android in material design, i want to add different web view in each tab bar, when i try to add it gives me much syntax errors.

here is the code:

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;

}

}

i thought to put :

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");

in each "case" and change the url

but this is the errors that i get:

Error:(33, 10) cannot find symbol method

setArguments(android.os.Bundle) Error:(39, 20) cannot find symbol

method getArguments() Error:(63, 48) cannot find symbol class

MyWebViewClient Error:(64, 50) cannot find symbol class

MyWebChromeClient Error:(69, 54) cannot find symbol class

JavaScriptInterface

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值