簡體   English   中英

webview無法全屏顯示

[英]webview is not taking full screen

在此處輸入圖片說明

我有兩個按鈕的簡單布局,如您在圖像中看到的,當我單擊google按鈕時,它在webview中打開了google網站,因為您看到它沒有全屏打開google網站,而是顯示了兩個按鈕,但是當我從我的主布局中刪除滾動條,然后webview在全屏上顯示google網站,我該如何解決此問題,因為我想在我的主布局中使用scrollview ..這是我的main.xml

XML文件

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <Button 
            android:id="@+id/btn_click_login"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:layout_weight="2"
            android:text="Google"/>

    <Button 
            android:id="@+id/btn_gmail"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:layout_weight="2"
            android:text="Gmail"/>

  <WebView 
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        >
 </WebView>

</LinearLayout>      
</ScrollView>

當我單擊google按鈕時,它會在webview中打開google網站,因為您看到它未在全屏模式下打開google網站

這是因為您可能正在使用具有相同XML布局的相同Activity ,其中還有其他widgets 但是解決方案並不困難。

1.首先使用一個窗口小部件WebView創建類似web.xml的內容。

2.然后創建另一個從Activity擴展的類,例如WebBrowser.java

3.將它作為<activity android:name=".WebBrowser"></activity>添加到您的Manifest.xml<activity android:name=".WebBrowser"></activity>

4.在WebBrowser類中,將使用setContentView(R.layout.web)設置布局並初始化WebView

5.單擊Google Button創建新的Intent並開始新的Activity

Intent i = new Intent(this, WebBrowser.class);
startActivity(i);


您的web.xml看起來像

<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="fill_parent"
        android:layout_height="fill_parent"
        />

</LinearLayout>


注意:要支持全屏,您可以使用

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM