WebView 没有填满设备或模拟器的整个屏幕
我正在开发一个 Android 应用程序,它在启动时加载一个 Web 应用程序。为了达到这个目的,我使用 webview 控件。我希望我的 webview 全屏显示,以便给用户带来原生的感觉。我尝试了所有显示 webthview 全屏的方法,但没有任何效果。我不知道我错过了什么。我需要这方面的帮助。下面我发布了我尝试过的代码片段,还附上了屏幕截图,显示了 webview 在模拟器和移动设备上的显示方式。
方法 1:尝试使用简单的基本代码
webbrowser.setWebViewClient(new MyWebViewClient());
webbrowser.getSettings().setJavaScriptEnabled(true);
webbrowser.loadUrl("http://google.com");
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
方法 2:尝试在清单文件中将主题设置为全屏
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
方法 3:尝试使用代码
//Full screen
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
方法 4:尝试使用 ChromeClient
mWebView.setWebChromeClient(new MyWebChromeClient());
mWebView.addJavascriptInterface(new DemoJavaScriptInterface(), "demo");
mWebView.loadUrl("http://google.com/");
方法 5:尝试在 main.xml 中仅定义没有布局的 webview
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview_compontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
/>
方法 6:还尝试通过将 webview 边缘与父级对齐来使用相对布局,
但没有任何效果对我有用。我测试的设备是 samsung Galaxy Tab,模拟器是 Android 2.3.3。在 7 英寸 Galaxy Tab 中,它显示在中间,四边有空白。而在模拟器中,它在底部留有空间。
如果有人能在这方面指导我,我真的很感激。
I am developing an android application which loads a web application when started. To achieve the purpose I am using webview control. I want my webview to be displayed full screen so that it will give native feel to the users. I tried all the methods to display webthview full screen but nothing is working. I dont know what I am missing. I need help on that. Below I am posting the code snippets that I tried also attached screenshots that shows how webview is displaying on emulator and mobile as well.
Method 1: Tried with simple basic code
webbrowser.setWebViewClient(new MyWebViewClient());
webbrowser.getSettings().setJavaScriptEnabled(true);
webbrowser.loadUrl("http://google.com");
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
Method 2: Tried setting theme as full screen in manifest file
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
Method 3: Tried doing it using code
//Full screen
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Method 4: Tried with ChromeClient
mWebView.setWebChromeClient(new MyWebChromeClient());
mWebView.addJavascriptInterface(new DemoJavaScriptInterface(), "demo");
mWebView.loadUrl("http://google.com/");
Method 5: Tried just defining webview without layout in main.xml
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview_compontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
/>
Method 6: Also tried with relative layout by aligning webview edges to parent
Nothing worked for me. The device I am testing with is samsung galaxy tab and emulator is Android 2.3.3. In 7 inch galaxy tab it is showing up in the middle and on four sides there are blank spaces. Whereas in emulator its leaving space at the bottom.
I really appreciate if someone can guide me on this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需在清单中添加以下代码:
>
just ad in manifest the following code:
>
mWebView.setWebChromeClient(new MyWebChromeClient());
从您的 Activity.java 文件中删除此 Java 代码
然后se,
mWebView.setWebChromeClient(new MyWebChromeClient());
remove this java code from your activity.java file
then se,
只需从布局中删除填充...
just remove the padding from your layout...