【发布时间】:2015-06-25 15:41:00
【问题描述】:
我正在制作一个包含 2 个按钮的应用程序,当用户单击这两个按钮中的任何一个时,我希望它们被重定向到网页。我已经制作了按钮和 webview 活动的 XML 代码。我还制作了 webview 活动 java 文件。我现在的问题是如何设置它以便当用户单击按钮时应用程序将启动 webview 活动?
另外,如何设置 webview 活动 java 从另一个按钮打开链接或另一个?
这些是我的按钮 XML 代码
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:src="@drawable/uninstall"
android:text="@string/uninstall_img"
android:autoLink="all"
android:layout_below="@+id/textView3"
android:layout_centerHorizontal="true" />
ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/donate"
android:src="@drawable/donate"
android:text="@string/about_link"
android:autoLink="all"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true" />
这是我的 webview 活动 java 代码
public class webviewacivity extends Activity {
private WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView.loadUrl("https://goo.gl/dUT1Ob");
mWebView = (WebView) findViewById(R.id.activity_main_webview);
}
}
注意
我没有在我的 activitymain.java 中添加按钮活动,因为它总是显示错误。如果您也向我展示该代码,我会很高兴。
我不是很擅长java,我只知道一点,所以我将复制并粘贴代码。 :)
【问题讨论】: