从片段调用带有javascript函数的活动
我正在尝试在加载片段后加载另一个活动。当我单击主页webview上的任何图标时,Toast命令正在工作,但intent不起作用。单击主页图标后,是否有方法加载其他活动。滑动菜单工作正常。我将此代码放在主java类文件中。其中as索引类文件不同。我两种方法都试过了,但都不管用。你能帮帮我吗 我的代码是:从片段调用带有javascript函数的活动,javascript,android,android-fragments,webview,fragment,Javascript,Android,Android Fragments,Webview,Fragment,我正在尝试在加载片段后加载另一个活动。当我单击主页webview上的任何图标时,Toast命令正在工作,但intent不起作用。单击主页图标后,是否有方法加载其他活动。滑动菜单工作正常。我将此代码放在主java类文件中。其中as索引类文件不同。我两种方法都试过了,但都不管用。你能帮帮我吗 我的代码是: public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstan
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
String url = "file:///android_asset/www/index.htm";
webView = (WebView) getView().findViewById(R.id.webviewhome);
webView.setWebViewClient(new MyBrowser());
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new WebAppInterface(getActivity()), "Android");
webView.loadUrl(url);
}
public class WebAppInterface {
Context mContext;
WebAppInterface(Context c) {
mContext = c;
}
@JavascriptInterface
public void LoadAboutGames() {
Toast.makeText(mContext, "This is About Games Activity", Toast.LENGTH_SHORT).show();
}
@JavascriptInterface
public void LoadShowInfo() {
Intent intent = new Intent(getActivity(), ShowInfo.class);
startActivity(intent);
}
@JavascriptInterface
public void LoadAppPhotos() {
Toast.makeText(mContext, "Hello", Toast.LENGTH_SHORT).show();
}
@JavascriptInterface
public void LoadAppVideos() {
Intent intent = new Intent(getActivity(), Videos.class);
startActivity(intent);
}
@JavascriptInterface
public void LoadExhibitors() {
Intent intent = new Intent(getActivity(), Exhibitor.class);
startActivity(intent);
}
@JavascriptInterface
public void LoadMessages() {
Intent intent = new Intent(getActivity(), AppMessages.class);
startActivity(intent);
}
@JavascriptInterface
public void LoadTickets() {
Intent intent = new Intent(getActivity(), Tickets.class);
startActivity(intent);
}
@JavascriptInterface
public void LoadContact() {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("file:///android_asset/www/contacts.htm"));
getActivity().startActivity(intent);
}
}
经过长时间的斗争,我解决了我的问题,我只需要使用这段代码,现在它的工作良好,正如我所期望的
FragmentManager FragmentManager=getFragmentManager();fragmentManager.beginTransaction().replace(R.id.frame_容器,新的ShowInfo()).commit() 试试这个。。。setWebChromeClient(新的WebChromeClient());经过长时间的努力,我解决了我的问题,我只需要使用这段代码,现在它工作正常,正如我所期望的FragmentManager FragmentManager=getFragmentManager();fragmentManager.beginTransaction().replace(R.id.frame_容器,新的ShowInfo()).commit();