【发布时间】:2015-01-14 16:03:21
【问题描述】:
我的应用程序包含一个 tab-widged 活动。在一个选项卡中,我显示了一个 web 视图,我想在该视图下显示几个按钮。
我发布的代码现在有效!
感谢您的帮助
package com.whateveryoulike.whateveryoulike;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class Activity_tab_reader extends Activity {
private WebView webView;
// entnimmt die url aus dem public static string und legt sie in der localen string mynewurl ab.
String MyNewUrl = Activity_Haupt.MyDocumentURL;
//String data = "<html><head></head><body>this should be my long long text...</body></html>";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_reader);
MyNewUrl = Activity_Haupt.MyDocumentURL;
webView = (WebView) findViewById(R.id.webview);
webView.loadUrl(MyNewUrl);
//Settings webview
webView.getSettings().setJavaScriptEnabled(true); // enable javascript
webView.getSettings().setSaveFormData(true);
final Activity activity = this;
webView.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
}
});
}
@Override
protected void onResume() {
super.onResume();
if(!MyNewUrl.equals(Activity_Haupt.MyDocumentURL)){
MyNewUrl = Activity_Haupt.MyDocumentURL;
webView.loadUrl(MyNewUrl);
}
}
}
这是 tabxml 文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/fh_blau"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3" >
<Button
android:id="@+id/btnRefresh"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="@+id/btnNext"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="@+id/btnCloseSearch"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/linear" />
</RelativeLayout>
感谢您的帮助
【问题讨论】:
-
“我几乎尝试了所有方法,但没有成功”我不确定你是否理解 "literal" 这个词,但你至少应该向我们展示你的最新尝试
-
你尝试过shotgun调试吗?
-
"按钮不存在!"你说得对。您认为应该在那里的按钮在哪里?您在
setContentView()中设置了网络视图,所以我不确定您还希望显示什么... -
@codeMagic 可能是这样。我来自德国,所以我的英语不是无懈可击的。添加了java代码。从一开始就打算这样做,但 stackoverflow 不断提醒我代码在代码区域之外....
-
好的,我已经链接到它,所以你可以理解它的含义。但这意味着绝对没有你没有尝试过的事情是不可能的。无论如何,我仍然不确定您希望看到的按钮在哪里。
标签: android android-layout button webview tabs