我的应用程序中的WebView显示为窗口,但我希望它是全屏的!这是它的屏幕截图:
这是我的代码:
public class DockViewerActivity extends Activity {
private WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWebView = new WebView(this);
setContentView(mWebView);
mWebView.loadUrl("file:///android_asset/1.html");
Toast.makeText(this, getString(R.string.loading), Toast.LENGTH_LONG).show();
}
}
答案 0 :(得分:4)
将高度和宽度设置为match_parent,如下所示:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/conrainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<WebView
android:id="@+id/webview"
android:layout_width="match_parent "
android:layout_height="match_parent "/>
</RelativeLayout>
删除您必须使用的状态栏:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
要删除标题栏,您必须使用:
requestWindowFeature(Window.FEATURE_NO_TITLE);
在设置内容视图之前必须设置上述两个功能,如下所示:
@Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.base_screen);
}
height
,width
设置为match_parent
,如:LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
mWebView .setLayoutParams(layoutParams);
现在就完成!! #cheers !!
答案 1 :(得分:1)
这是我的代码,以实现全屏webview。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
setContentView(R.layout.activity_main);
myWebView = (WebView)findViewById(R.id.webview);
...
}
此活动的XML布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mains"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
...
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible"
/>
...
</RelativeLayout>