android全屏显示webview
- MainActivity.java文件修改
package com.example.a1.cqmt;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.view.Window;
import android.view.WindowManager;
public class MainActivity extends AppCompatActivity {
private WebView webview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Window window = getWindow();
//隐藏标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏状态栏
//定义全屏参数
int flag=WindowManager.LayoutParams.FLAG_FULLSCREEN;
//设置当前窗体为全屏显示
window.setFlags(flag, flag);
// setContentView(R.layout.activity_main);
//实例化WebView对象
webview = new WebView(this);
//设置WebView属性,能够执行Javascript脚本
webview.getSettings().setJavaScriptEnabled(true);
//加载需要显示的网页
//webview.loadUrl("file:///android_asset/index.html"); //显示本地网页
webview.getSettings().setAllowFileAccessFromFileURLs(true);
webview.getSettings().setAllowUniversalAccessFromFileURLs(true);
webview.loadUrl("https://www.baidu.com");//显示远程网页
//设置Web视图
setContentView(webview);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack() ){
webview.goBack();
return true;
}
return false;
}
}
- AndroidManifest.xml修改
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.a1.cqmt">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.NoActionBar">
<activity android:name=".MainActivity" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
android studio快捷键:
- All+Enter补全Android的import