使用 Android 我遇到了这个问题:如何让抽屉导航菜单列表为每个列表项打开一个 webview 以及如何在没有列表项被点击时加载默认 webview?
我已经构建了应用程序的布局。我有抽屉,我有操作栏,我有应该加载不同 URL 的 webview(由抽屉列表项管理)。
在 Main.java(主要 Activity java 文件)中,我放了类似的内容:
String myUrl = "http://www.mywebsite.com";
WebView myWebView = (WebView) this.findViewById(R.id.webView);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadUrl(myUrl);
我看到的是什么:(
此外,关于如何让单个 drwer 列表项在 webview 中更改 URL,我几乎没有什么线索。 还是我不应该那样做?
任何帮助、建议和教程都将不胜感激。 谢谢。
最佳答案
I have what must be for me the webview that should load the different URLs (managed by the drawer list items).
查看 NavigationDrawer
的培训部分,它看起来像这样:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
如您所见,实际的滑动菜单是一个ListView
。所以在你的 MainActivity
中你会做两件事:
- 为此
ListView
设置适配器 - 设置
onItemClickListener
每当单击一个项目时,您将更改加载到 WebView
中的 URL。
how to have a default webview loaded when no list item has been tapped?
在您的 MainActivity
中,只需加载默认 URL,很简单。
关于java - 抽屉导航打开不同的网页 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26181917/