package com.nsgk.ruralWeb; import android.annotation.SuppressLint; import android.content.Intent; import android.os.Bundle; import android.view.KeyEvent; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.RelativeLayout; import com.just.agentweb.AgentWeb; import com.just.agentweb.DefaultWebClient; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; /** * An example full-screen activity that shows and hides the system UI (i.e. * status bar and navigation/system bar) with user interaction. */ public class FullscreenActivity extends AppCompatActivity { private AgentWeb mAgentWeb; @SuppressLint("SetJavaScriptEnabled") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fullscreen); // init(); mAgentWeb = AgentWeb.with(this)// .setAgentWebParent((RelativeLayout) findViewById(R.id.ll), -1, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))//传入AgentWeb的父控件。 .useDefaultIndicator(-1, 3)//设置进度条颜色与高度,-1为默认值,高度为2,单位为dp。 .setWebViewClient(new com.just.agentweb.WebViewClient() { })//WebViewClient , 与 WebView 使用一致 ,但是请勿获取WebView调用setWebViewClient(xx)方法了,会覆盖AgentWeb DefaultWebClient,同时相应的中间件也会失效。 .setSecurityType(AgentWeb.SecurityType.STRICT_CHECK) //严格模式 Android 4.2.2 以下会放弃注入对象 ,使用AgentWebView没影响。 .setMainFrameErrorView(R.layout.agentweb_error_page, -1) //参数1是错误显示的布局,参数2点击刷新控件ID -1表示点击整个布局都刷新, AgentWeb 3.0.0 加入。 .setOpenOtherPageWays(DefaultWebClient.OpenOtherPageWays.ASK)//打开其他页面时,弹窗质询用户前往其他应用 AgentWeb 3.0.0 加入。 .interceptUnkownUrl() //拦截找不到相关页面的Url AgentWeb 3.0.0 加入。 .createAgentWeb()//创建AgentWeb。 .ready()//设置 WebSettings。 .go("http://218.59.175.43:96/agriculturalTrusteeship/index"); //WebView载入该url地址的页面并显示。 } @Override protected void onPause() { mAgentWeb.getWebLifeCycle().onPause(); super.onPause(); } @Override protected void onResume() { mAgentWeb.getWebLifeCycle().onResume(); super.onResume(); } @Override protected void onDestroy() { mAgentWeb.getWebLifeCycle().onDestroy(); super.onDestroy(); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) { // mWebView.goBack(); // return true; // } if (mAgentWeb.handleKeyEvent(keyCode, event)) { return true; } return super.onKeyDown(keyCode, event); } @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); } }