我已經創建了一個webview作爲覆蓋在另一個webview上,並懷疑關於第二個webview的後退按鈕實現。我的目標是如果我點擊後退按鈕它應該來到第一個webview。這是我的XML頁面:後退按鈕功能不能正常工作
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="com.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>
這是我的後退按鈕
news.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
exWebView.setVisibility(View.GONE);
mWebView.setVisibility(View.VISIBLE);
}
});
現在寫的。如果我點擊後退按鈕後functinality不工作和覆蓋的WebView內容的功能(第二個網頁視圖)會放大,就好像放大一樣。請引導我在我的代碼中。是否包含任何錯誤? 在此先感謝。
編輯
我發現,如果我點擊後退按鈕它會第一web視圖,但它是自動重新回來的第二web視圖和它發生得這麼快。我通過使用吐司發現了這一點。
嘗試寫setOnClick後'news.bringToFront()'權。功能後 –
? –
是的..試試吧。或者把它寫成你的onCreate的最後一行。嘗試兩種方式,看看它是否工作? –