1
所以,我对Android开发相当陌生,于是决定 - 在开始一些摆弄之后 - 让我的第一个完整的应用程序带有导航抽屉的应用程序。理想情况下,我想要一个WebView,如果您在导航抽屉中选择一个项目,URL将会更改。例如:导航抽屉由以下列表组成:Google,Stackoverflow,Facebook和Twitter。如果您点击其中的一个,则正确的网址会被推送到网络视图。如何通过单击按钮来更改webview的url?
我开始使用Google的代码。具有导航抽屉的示例应用程序,带有行星图像。我改变了一些东西,但是我目前坚持的步骤是点击一个项目和webview改变的那一步。下面你可以看到一些代码片段:
fragment_planet.xml
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:gravity="center"
android:padding="32dp" />
MainActivity
private void selectItem(int position) {
// update the main content by replacing fragments
Fragment fragment = new PlanetFragment();
Bundle args = new Bundle();
args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
fragment.setArguments(args);
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
// update selected item and title, then close the drawer
mDrawerList.setItemChecked(position, true);
setTitle(mPlanetTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
}
我希望有人能帮助我走出这一点,因为我可以”找到任何文件。