android 如何制作全屏网络视图

idfiyjo8  于 2023-01-15  发布在  Android
关注(0)|答案(7)|浏览(190)

如何使一个android应用程序的webview全屏。我已经添加了一个布局xml文件的webview,但它并没有延伸到布局的边缘,有一些沿着webview的边的边缘类型。我还添加了一个图像,给予你们一个什么样的实际上是什么样子的提示。

我说的是webview周围的空间,而不是通知栏或标题栏
下面是布局代码:

<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>
hpcdzsge

hpcdzsge1#

从上述代码中删除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中,可能包含那些留下一些空间的标记。

cbwuti44

cbwuti442#

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

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

vvppvyoh3#

将网络视图放入对话框弹出窗口。

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();
gywdnpxw

gywdnpxw4#

安卓版本:4.2.2-器械:织女星平板电脑
WebView隐藏状态和系统栏,并显示完整的屏幕我按照这些步骤.

    • 安卓清单. 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>
    • 主要活动. 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);

上述过程为我工作,我的应用程序显示在完整的屏幕。

clj7thdc

clj7thdc5#

您可以在res/values文件夹中的dimens.xml中设置维度。默认情况下为16 dp。因此可以相应地设置它。

pkln4tw6

pkln4tw66#

您应该更改相对布局设置。并删除填充设置,如果有任何在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">
5lhxktic

5lhxktic7#

来自文件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 Level 8和更高级别中重命名为MATCH_PARENT),这意味着视图希望与其父视图一样大(减去填充)
https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html

相关问题