[英]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.