2013-11-24 150 views
13

如何製作android應用程序的全屏webview。我已將webview添加到佈局xml文件中,但直到佈局的邊緣才展開,沿着web視圖的所有邊都有一些類型的邊距。我還添加了一個圖像,讓你們知道它看起來是什麼樣子。如何製作全屏webview

What i am talking about is the space all around the webview, not the notification bar or the title bar

什麼,我說的是空間的限制web視圖,而不是通知欄或標題欄

這裏的佈局代碼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
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" 
tools:context=".WebView" > 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:text="Shake/Tilt Your Phone To Get Accelerometer Motion Alerts" /> 

<WebView 
    android:id="@+id/webview" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" /> 

</RelativeLayout> 
+0

您可以發佈烏爾佈局XM l代碼請嗎? –

+0

@JohnJared剛剛添加了上面的代碼 – Arihant

回答

17

從上面的代碼中刪除padding tags -

android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 

它會做的工作,也一定要刪除HTML的利潤率/填充你所渲染到可能含有留下一定的空間,這些標籤的WebView。

+0

我剛剛添加了XML代碼的問題。請給它看看 – Arihant

+0

即使填充值爲零,仍然顯示一些空間,你能解釋一下原因嗎?我刪除了填充並固定。 – MAK

7

只需添加(或在AndroidManifest.xml文件中使用以下行更改)活動的android:theme屬性

android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
0

您可以在res/values文件夾中找到的dimens.xml中設置尺寸。默認情況下它是16dp。所以可以相應地設置它。

enter image description here

3

的Android版本:4.2.2 - 設備:維加平板

的WebView隱藏狀態和系統欄和顯示屏幕完全我跟着這些步驟。

AndroidManifest.xml中

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name"> 
    <activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" 
     android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

MainActivity.java

super.onCreate(savedInstanceState); 
getWindow().getDecorView().setSystemUiVisibility(0x10); 
setContentView(R.layout.activity_main); 
String url = "http://edition.cnn.com/"; 
WebView webView = (WebView) findViewById(R.id.webView); 
webView.getSettings().setJavaScriptEnabled(true); 
webView.getSettings().setUserAgentString("Desktop"); 
webView.loadUrl(url); 

上述過程的工作,我和我的應用程序顯示在屏幕上完成。

0

您應該更改相對佈局設置。並刪除填充設置,如果有的話在webview上的XML文件。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    tools:context=".MainActivity" 
 
    android:id="@+id/frame">

0

認沽web視圖中的對話框彈出窗口。

WebView webview = new WebView(this/*put your activity object*/); 
    webview.getSettings().setLoadWithOverviewMode(true); 
    webview.getSettings().setUseWideViewPort(false); 
    webview.getSettings().setSupportZoom(false); 
    webview.getSettings().setJavaScriptEnabled(true); 
    webview.setBackgroundColor(Color.TRANSPARENT); 
    webview.loadUrl("http://www.awwwards.com/websites/responsive-design/"); 

    RelativeLayout.LayoutParams paramsWebView = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); 
    Dialog dialog = new Dialog(this/*put your activity object*/, android.R.style.Theme_Black_NoTitleBar_Fullscreen); 
    dialog.addContentView(webview, paramsWebView); 
    dialog.show(); 
0

從文檔https://developer.android.com/guide/webapps/webview.html

<?xml version="1.0" encoding="utf-8"?> 
<WebView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/webview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
/> 

FILL_PARENT,這意味着該視圖希望成爲作爲其父(負填充)

一樣大(在API級別8和更高的重命名MATCH_PARENT)

https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html