【发布时间】:2014-09-07 17:53:40
【问题描述】:
我在活动 WebViewActivity 中有 WebView,在 main_activity 中有一些图像按钮。 你能帮我吗?我需要当我单击 imagebutton1 时,它会打开 WebViewActivity 并在 WebView 等 google.com 中打开。当我单击 imagebutton2 时,它将打开 etc yahoo.com 。我是编程新手,而且我不会说英语(我的英语不好,因为我来自捷克代表)。感谢您的帮助!
主要活动
package com.tona.arcig;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton() {
ImageButton imgbutton1 = (ImageButton) findViewById(R.id.imageButton1);
imgbutton1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "I like trains", Toast.LENGTH_LONG).show();
}
});
}
}
WEBVIEW活动
package com.tona.arcig;
import android.app.Activity;
import android.os.Bundle;
public class WebviewActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
}
}
活动主 XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:contentDescription="@string/suplovani"
android:src="@drawable/suplovani" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:contentDescription="@string/rozvrh"
android:src="@drawable/rozvrh" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:contentDescription="@string/prihlasovani"
android:src="@drawable/prihlasovani" />
<ImageButton
android:id="@+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:contentDescription="@string/email"
android:src="@drawable/email" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/imageButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:contentDescription="@string/email"
android:src="@drawable/moodle" />
<ImageButton
android:id="@+id/imageButton6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:contentDescription="@string/kdm"
android:src="@drawable/jidelna" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageButton
android:id="@+id/imageButton7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/o_aplikaci"
android:src="@drawable/about" />
</LinearLayout>
</LinearLayout>
活动网页浏览 XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
清单
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
字符串
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="suplovani">Suplování</string>
<string name="rozvrh">Rozvrh hodin</string>
<string name="prihlasovani">Přihlašování do systému</string>
<string name="email">Email</string>
<string name="moodle">Moodle</string>
<string name="kdm">KDM</string>
<string name="o_aplikaci">O Aplikaci</string>
<string name="app_name">Arcig.CZ</string>
<string name="title_webview">Arcig.CZ</string>
</resources>
谢谢。
【问题讨论】:
标签: android android-activity webview