Skip to content

Commit

Permalink
WebView 默认支持缩放网页
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyLemon committed Feb 5, 2024
1 parent 4d48ae3 commit e03174a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
Expand Down Expand Up @@ -62,6 +63,7 @@ public static Intent createIntent(Context context, String title, String url) {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); // AndroidManifest 中设置导致 gradle 编译 merge 报错
setContentView(R.layout.web_view_activity, this);//传this是为了全局滑动返回

url = StringUtil.getCorrectUrl(getIntent().getStringExtra(INTENT_URL));
Expand Down Expand Up @@ -115,6 +117,11 @@ public void initData() {

WebSettings webSettings = wvWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setSupportZoom(true);
webSettings.setDisplayZoomControls(false);

wvWebView.requestFocus();

Expand Down
4 changes: 3 additions & 1 deletion ZBLibrary/src/main/res/layout/web_view_activity.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llWebView"
style="@style/activity_page" >
style="@style/activity_page"
android:splitMotionEvents="true"
>

<RelativeLayout style="@style/topbar_bg" >

Expand Down

0 comments on commit e03174a

Please sign in to comment.