一个 webview 覆盖在另一个 webview 上 [英] A webview overlay over another webview
本文介绍了一个 webview 覆盖在另一个 webview 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 webview,如果我点击该页面中的任何链接,它会打开另一个 webview.现在我想将第二个 webview 覆盖在第一个 webview 上.如果我单击第二个 webview 上的按钮,它应该关闭.这是我的 XML 页面.
I have a webview in which If I click any link in that page it opens another webview. Now I want to overlay the second webview over first webview. And If I click the button on the second webview it should close. This is my XML page.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="app.MainActivity"
tools:showIn="@layout/activity_main">
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/activity_main_webview"/>
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:id="@+id/external_webview">
</WebView>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:id="@+id/ext_link"
android:layout_height="fill_parent">
<RelativeLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:background="#FFFFFF"
android:layout_height="45dp"
android:weightSum="1">
<Button
android:id="@+id/backtonews"
android:layout_marginTop="7dp"
android:layout_width="190dp"
android:layout_height="30dp"
android:background="@drawable/button">
</Button>
</RelativeLayout>
</RelativeLayout>
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_below="@id/toolbar"
android:visibility="gone"
android:layout_height="match_parent"></FrameLayout>
<RelativeLayout
android:id="@+id/container_help"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#88666666"
android:visibility="invisible" >
<ImageView
android:id="@+id/image_help"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="false"
android:contentDescription="@string/help_screen"
android:scaleType="fitXY"
android:src="@drawable/userguide"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" />
</RelativeLayout>
我该怎么做?
推荐答案
我会使用 Framelayout.像这样:
I would use a Framelayout. Like this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<WebView
android:id="@+id/webview2"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<WebView
android:id="@+id/webview1"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
代码:
webview1 = findViewById(R.id.webview1);
webview2 = findViewById(R.id.webview2);
button = findViewById(R.id.backtonews);
webview1.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
webview2.loadUrl(url);
webview1.setVisibility(View.GONE);
return true;
}
});
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
webview1.setVisility(View.VISIBLE);
webview2.setVisility(View.GONE);
}
});
这篇关于一个 webview 覆盖在另一个 webview 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文