如何让 Android 的前端页面像 iOS 一样“优雅”?

如何让Android的前端页面像iOS一样“优雅”?

作者:方英杰(崇之)

最近在调研前端页面适配 Android 端异形屏的方案,调研过程中发现了一些比较有意思的点,本文主要是做一个总结。

一、提出问题

首先,我们需要知道 Android 上的前端适配面临着什么问题。

问题其实很简单,和原生 UI 视图相比,前端页面无法直接获取到设备的部分控件信息,如状态栏高度、导航栏高度等,假如设备是异形屏,还意味着前端不知道挖孔/刘海的位置、尺寸等信息。因此如果前端页面是一个全屏的页面,就会面临着内容会被这些控件遮挡的风险。

同样是移动端设备,iOS 是怎么做的呢?

实际上,早在 iOS 11 时期,Apple 就针对前端推出了一个 safe-area-inset-* 的概念,它作为一组四个环境变量,在 WebKit 中提供。前端可以通过 env() 函数或是 constant() 函数(已废弃)来获取到对应的值,这四个值代表着前端页面在四个方向上需要留出的 Padding,遵循此配置就能保证前端页面不会被其他控件遮挡。下文中我们统一把这个能力称为 Safe Area。

由于 iOS 这项能力支持的早,加上 Apple 新系统的覆盖率一向很高,所以前端的适配推进的很快。以钉钉为例,目前钉钉内的前端页面在 iOS 上的显示效果比起 Android 上要明显好得多。

Android 效果

iOS 效果

那么 Android 这边有没有类似的东西呢?

实际上,在 iOS 推出这个特性之后,其他比较主流的浏览器内核都相继跟进了这个能力。我们知道 Android 上实际使用的是 Chromium 内核来支撑前端内容显示的(原生方案),其从 69 版本开始已经支持了这个能力。而对于像是钉钉使用的 UC 内核,从 3.0 开始也对此做了支持。

既然都已经支持了,为什么 Android 这边还是无法做到对齐 iOS 的效果呢?

首先就是浏览器内核版本限制,我们知道 Android 的 Chromium 内核是打包在一个独立应用里的,可以单独更新,这样做的好处是内核有什么重要的新特性或安全修复可以马上升级上去,不用跟随长周期的系统更新做升级。因此造成了 Chromium 内核在 Android 各个品牌手机上的版本存在比较严重的碎片化问题,也就导致了我们完全无法保证一些系统版本较低的机器上面带的内核足够支持我们想要的能力。

其次就是 Android 系统的这个 Safe Area 的能力有 bug,它提供的值总是会诡异的变成 0,这就导致了虽然浏览器内核早早提供了这项能力,但是存在一定的稳定性问题。

最后就是即使这个能力在 Android 上生效了,最终所展现的效果却不一定是我们想要的。下面这张截图就很好的体现了这一点。在横屏状态下只有左侧有值,而没有给顶部的状态栏区域留出足够的 Padding。

所以为什么明明是在 iOS 上信手拈来的事,到了 Android 上就各种翻车呢,我觉得找到 Android 系统侧是怎么提供 Safe Area 的值很重要。

二、分析问题

下面是 Android 侧对 Safe Area 支持的底层实现分析过程。

我们使用的 WebView 位于 webkit 包下,但实际上这个包在 Android4.4 就已经废弃了,实际的能力是通过委托到 WebViewProvider 来实现的,这点从 WebView 的注释以及方法中的实际调用就能看出来。

// Implementation notes.// The WebView is a thin API class that delegates its public API to a backend WebViewProvider// class instance. WebView extends {@link AbsoluteLayout} for backward compatibility reasons.// Methods are delegated to the provider implementation: all public API methods introduced in this// file are fully delegated, whereas public and protected methods from the View base classes are// only delegated where a specific need exists for them to do so.@Widgetpublic class WebView extends AbsoluteLayout        implements ViewTreeObserver.OnGlobalFocusChangeListener,        ViewGroup.OnHierarchyChangeListener, ViewDebug.HierarchyHandler {  ...     public void loadUrl(@NonNull String url, @NonNull Map<String, String> additionalHttpHeaders) {    checkThread();    mProvider.loadUrl(url, additionalHttpHeaders);  }  ...}

WebViewProvider 的原生实现就是 WebViewChromium,至于在 WebView 中是如何获取到 WebViewChromium 实例的,这块的分析文章还是很多的,感兴趣的同学可以自行检索相关内容。在 WebViewChromium 中我们的 WebView 作为一个参数传入:

/** * This class is the delegate to which WebViewProxy forwards all API calls. * * Most of the actual functionality is implemented by AwContents (or WebContents within * it). This class also contains WebView-specific APIs that require the creation of other * adapters (otherwise org.chromium.content would depend on the webview.chromium package) * and a small set of no-op deprecated APIs. */@SuppressWarnings("deprecation")@Lifetime.WebViewclass WebViewChromium        implements WebViewProvider,                WebViewProvider.ScrollDelegate,                WebViewProvider.ViewDelegate,                SmartClipProvider {    public WebViewChromium(            WebViewChromiumFactoryProvider factory,            WebView webView,            WebView.PrivateAccess webViewPrivate,            boolean shouldDisableThreadChecking) {        ...    }}

传入的 WebView 将在后续的流程中起到非常重要的作用。

在 WebViewChromium 的初始化阶段,会构造了一个 AwContents 对象,接着传递我们的 WebView:

private void initForReal() {  ...  mAwContents = new AwContents(                  browserContext,                  mWebView,                  mContext,                  new InternalAccessAdapter(),                  new WebViewNativeDrawFunctorFactory(),                  mContentsClientAdapter,                  mWebSettings.getAwSettings(),                  new AwContents.DependencyFactory());  ...}

这个类和我们当前要探讨的内容关联不大,但是在整个 WebView 能力实现过程中起到了至关重要的作用。在 AwContents 中,和 Safe Area 有关联的是下面这段代码:

public AwContents(        AwBrowserContext browserContext,        ViewGroup containerView,        Context context,        InternalAccessDelegate internalAccessAdapter,        NativeDrawFunctorFactory nativeDrawFunctorFactory,        AwContentsClient contentsClient,        AwSettings settings,        DependencyFactory dependencyFactory) {  ...  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P                    && AwFeatureMap.isEnabled(AwFeatures.WEBVIEW_DISPLAY_CUTOUT)) {    mDisplayCutoutController =        new AwDisplayCutoutController(                new AwDisplayCutoutController.Delegate() {                    @Override                    public float getDipScale() {                        WindowAndroid windowAndroid =                                mWindowAndroid.getWindowAndroid();                        return windowAndroid.getDisplay().getDipScale();                    }
                    @Override                    public void setDisplayCutoutSafeArea(                            AwDisplayCutoutController.Insets insets) {                        if (mWebContents == null) return;                        mWebContents.setDisplayCutoutSafeArea(                                insets.toRect(mCachedSafeAreaRect));                    }                },                containerView);  }  ...}

这里构造了一个 AwDisplayCutoutController 对象,这个类的主要职责是管控 Android 上的 DisplayCutout 相关的逻辑,实际上就是挖孔/刘海。我们可以看到在构造对象时,实现了一个 setDisplayCutoutSafeArea 的方法。这个方法名是不是要素察觉。先不急着看方法的实现,我们先看一下方法是在哪里被调用的:

public AwDisplayCutoutController(Delegate delegate, View containerView) {      mDelegate = delegate;      mContainerView = containerView;      registerContainerView(containerView);  }

可以看到在 AwDisplayCutoutController 的构造方法里,除了相关的变量赋值外,还有一个 registerContainerView 的方法调用,入参为我们传入的 WebView,看看这个方法做了什么:

/** * Register a container view to listen to window insets. * * Note that you do not need to register the containerView. * * @param containerView A container View, such as fullscreen view. */public void registerContainerView(View containerView) {    if (DEBUG) Log.i(TAG, "registerContainerView");    // For Android P~R, we set the listener in WebView's constructor.    // Once we set the listener, we will no longer get View#onApplyWindowInsets(WindowInsets).    // If the app sets its own listener after WebView's constructor, then the app can override    // our logic, which seems like a natural behavior.    // For Android S, WebViewChromium can get onApplyWindowInsets(WindowInsets) call, so we do    // not need to set the listener.    // TODO(crbug.com/40699457): do not set listener and plumb WebViewChromium to handle    // onApplyWindowInsets in S and above.    containerView.setOnApplyWindowInsetsListener(            new View.OnApplyWindowInsetsListener() {                @Override                public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {                    // Ignore if this is not the current container view.                    if (view == mContainerView) {                        return AwDisplayCutoutController.this.onApplyWindowInsets(insets);                    } else {                        if (DEBUG) Log.i(TAG, "Ignoring onApplyWindowInsets on View: " + view);                        return insets;                    }                }            });}

其实,就只是简单的给我们的 WebView 设置了一个 OnApplyWindowInsetsListener 的监听。只是由于这个方法是在构造函数中调用的,所以设置的时机非常早,在此之后如果我们给 WebView 设置自己的 OnApplyWindowInsetsListener 监听就会把这个监听给覆盖掉。

AwDisplayCutoutController 中设置这个监听其实就只是为了触发自己的 onApplyWindowInsets 方法,方法如下:

/** * Call this when window insets are first applied or changed. * * @see View#onApplyWindowInsets(WindowInsets) * @param insets The window (display) insets. */@VisibleForTestingpublic WindowInsets onApplyWindowInsets(final WindowInsets insets) {    if (DEBUG) Log.i(TAG, "onApplyWindowInsets: " + insets.toString());    // TODO(crbug.com/40699457): add a throttling logic.    DisplayCutout cutout = insets.getDisplayCutout();    // DisplayCutout can be null if there is no notch, or layoutInDisplayCutoutMode is DEFAULT    // (before R) or consumed in the parent view.    if (cutout != null) {        Insets displayCutoutInsets =                new Insets(                        cutout.getSafeInsetLeft(),                        cutout.getSafeInsetTop(),                        cutout.getSafeInsetRight(),                        cutout.getSafeInsetBottom());        onApplyWindowInsetsInternal(displayCutoutInsets);    }    return insets;}

可以看到在这个方法中,通过 WindowInsets 拿到了 DisplayCutout,并使用它的值构造了一个 Insets 对象,传给了 onApplyWindowInsetsInternal 方法,如果 WindowInsets 中没有 DisplayCutout,那么是不会接着往下调用的。在 onApplyWindowInsetsInternal 中,将计算后的 Insets 值传给了 Delegate 的 setDisplayCutoutSafeArea 方法:

/** * Call this when window insets are first applied or changed. * * Similar to {@link onApplyWindowInsets(WindowInsets)}, but accepts * Rect as input. * * @param displayCutoutInsets Insets to store left, top, right, bottom insets. */@VisibleForTestingpublic void onApplyWindowInsetsInternal(final Insets displayCutoutInsets) {    float dipScale = mDelegate.getDipScale();    // We only apply this logic when webview is occupying the entire screen.    adjustInsetsForScale(displayCutoutInsets, dipScale);
    if (DEBUG) {        Log.i(                TAG,                "onApplyWindowInsetsInternal. insets: "                        + displayCutoutInsets                        + ", dip scale: "                        + dipScale);    }    // Note that internally we apply this logic only when the display is in fullscreen mode.    // See AwDisplayModeController for more details on how we check the fullscreen mode.    mDelegate.setDisplayCutoutSafeArea(displayCutoutInsets);}

现在我们就回到了 AwContents 类中,setDisplayCutoutSafeArea 的实现如下:

@Overridepublic void setDisplayCutoutSafeArea(        AwDisplayCutoutController.Insets insets) {    if (mWebContents == null) return;    mWebContents.setDisplayCutoutSafeArea(            insets.toRect(mCachedSafeAreaRect));}

实际上是调用了 WebContents 的 setDisplayCutoutSafeArea 方法,这个方法实际上会调用到 C++ 的能力:

@Overridepublic void setDisplayCutoutSafeArea(Rect insets) {    if (mNativeWebContentsAndroid == 0) return;    WebContentsImplJni.get()            .setDisplayCutoutSafeArea(                    mNativeWebContentsAndroid,                    insets.top,                    insets.left,                    insets.bottom,                    insets.right);}

一路跟踪调用链到这里,我们其实已经基本能确定前端拿到的 Safe Area 的值就是从 WindowInsets 的 DisplayCutout 中获取的了。为了进一步验证这个推断,我们可以看一下 C++ 层的实现:

#if BUILDFLAG(IS_ANDROID)
void WebContentsImpl::SetDisplayCutoutSafeArea(gfx::Insets insets) {  OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::SetDisplayCutoutSafeArea");  if (safe_area_insets_host_) {    safe_area_insets_host_->SetDisplayCutoutSafeArea(insets);  }}
#endif
void DisplayCutoutHostImpl::SetDisplayCutoutSafeArea(gfx::Insets insets) {  insets_ = insets;
  if (current_rfh_)    SendSafeAreaToFrame(current_rfh_.get(), insets);}
void SafeAreaInsetsHost::SendSafeAreaToFrame(RenderFrameHost* rfh,                                             gfx::Insets insets) {  blink::AssociatedInterfaceProvider* provider =      rfh->GetRemoteAssociatedInterfaces();  if (!provider) {    return;  }
  mojo::AssociatedRemote<blink::mojom::DisplayCutoutClient> client;  provider->GetInterface(client.BindNewEndpointAndPassReceiver());  client->SetSafeArea(insets);}
void DisplayCutoutClientImpl::SetSafeArea(const gfx::Insets& safe_area) {  frame_->GetDocument()->GetPage()->SetMaxSafeAreaInsets(frame_, safe_area);}
void Page::SetMaxSafeAreaInsets(LocalFrame* setter, gfx::Insets max_safe_area) {  max_safe_area_insets_ = max_safe_area;
  // When the SAI is changed when DynamicSafeAreaInsetsEnabled, the SAI for the  // main frame needs to be set per browser controls state.  if (RuntimeEnabledFeatures::DynamicSafeAreaInsetsEnabled() &&      setter->IsMainFrame()) {    UpdateSafeAreaInsetWithBrowserControls(GetBrowserControls(), true);  } else {    SetSafeAreaEnvVariables(setter, max_safe_area);  }}
void Page::UpdateSafeAreaInsetWithBrowserControls(    const BrowserControls& browser_controls,    bool force_update) {  DCHECK(RuntimeEnabledFeatures::DynamicSafeAreaInsetsEnabled());
  if (Fullscreen::HasFullscreenElements() && !force_update) {    LOG(WARNING) << "Attempt to set SAI with browser controls in fullscreen.";    return;  }
  // Adjust the top / left / right is not needed, since they are set when  // display insets was received at |SetSafeArea()|.  int inset_bottom = GetMaxSafeAreaInsets().bottom();  int bottom_controls_full_height = browser_controls.BottomHeight();  float control_ratio = browser_controls.BottomShownRatio();  float dip_scale = GetVisualViewport().ScaleFromDIP();
  // As control_ratio decrease, safe_area_inset_bottom will be added to the web  // page to keep the bottom element out from the display cutout area.  float safe_area_inset_bottom =      std::max(0.f, inset_bottom - control_ratio * bottom_controls_full_height /                                       dip_scale);
  gfx::Insets new_safe_area = gfx::Insets().TLBR(      max_safe_area_insets_.top(), max_safe_area_insets_.left(),      safe_area_inset_bottom, max_safe_area_insets_.right());  if (new_safe_area != applied_safe_area_insets_ || force_update) {    applied_safe_area_insets_ = new_safe_area;    SetSafeAreaEnvVariables(DeprecatedLocalMainFrame(), new_safe_area);  }}
// staticvoid SetSafeAreaEnvVariables(LocalFrame* frame, const gfx::Insets& safe_area) {  DocumentStyleEnvironmentVariables& vars =      frame->GetDocument()->GetStyleEngine().EnsureEnvironmentVariables();  vars.SetVariable(UADefinedVariable::kSafeAreaInsetTop,                   StyleEnvironmentVariables::FormatPx(safe_area.top()));  vars.SetVariable(UADefinedVariable::kSafeAreaInsetLeft,                   StyleEnvironmentVariables::FormatPx(safe_area.left()));  vars.SetVariable(UADefinedVariable::kSafeAreaInsetBottom,                   StyleEnvironmentVariables::FormatPx(safe_area.bottom()));  vars.SetVariable(UADefinedVariable::kSafeAreaInsetRight,                   StyleEnvironmentVariables::FormatPx(safe_area.right()));}
void StyleEnvironmentVariables::SetVariable(UADefinedVariable variable,                                            const String& value) {  SetVariable(GetVariableName(variable, GetFeatureContext()), value);}
// staticconst AtomicString StyleEnvironmentVariables::GetVariableName(    UADefinedVariable variable,    const FeatureContext* feature_context) {  switch (variable) {    case UADefinedVariable::kSafeAreaInsetTop:      return AtomicString("safe-area-inset-top");    case UADefinedVariable::kSafeAreaInsetLeft:      return AtomicString("safe-area-inset-left");    case UADefinedVariable::kSafeAreaInsetBottom:      return AtomicString("safe-area-inset-bottom");    case UADefinedVariable::kSafeAreaInsetRight:      return AtomicString("safe-area-inset-right");    case UADefinedVariable::kKeyboardInsetTop:      return AtomicString("keyboard-inset-top");    case UADefinedVariable::kKeyboardInsetLeft:      return AtomicString("keyboard-inset-left");    case UADefinedVariable::kKeyboardInsetBottom:      return AtomicString("keyboard-inset-bottom");    case UADefinedVariable::kKeyboardInsetRight:      return AtomicString("keyboard-inset-right");    case UADefinedVariable::kKeyboardInsetWidth:      return AtomicString("keyboard-inset-width");    case UADefinedVariable::kKeyboardInsetHeight:      return AtomicString("keyboard-inset-height");    case UADefinedVariable::kTitlebarAreaX:      return AtomicString("titlebar-area-x");    case UADefinedVariable::kTitlebarAreaY:      return AtomicString("titlebar-area-y");    case UADefinedVariable::kTitlebarAreaWidth:      return AtomicString("titlebar-area-width");    case UADefinedVariable::kTitlebarAreaHeight:      return AtomicString("titlebar-area-height");    default:      break;  }
  NOTREACHED_IN_MIGRATION();}
void StyleEnvironmentVariables::SetVariable(const AtomicString& name,                                            const String& value) {  data_.Set(name,            CSSVariableData::Create(value, false /* is_animation_tainted */,                                    false /* needs_variable_resolution */));  InvalidateVariable(name);}

通过层层调用,我们最终看到了朝思暮想的 safe-area-inset-* 属性。至此,Android 端支持 Safe Area 的底层逻辑我们已经完全搞清楚了。

三、总结

总的来说,Android 端对前端 Safe Area 的支持其实就只是简单的把端上的 WindowInsets 中的 DisplayCutout 抛给了前端,只是其实现的方式不太优雅。

首先 View 只支持设置一个 OnApplyWindowInsetsListener 监听,这又是个公开方法,指望业务层完全不去碰这个方法是不可能的,也就导致了在实际使用时 safe-area-inset-* 属性总是会"莫名其妙"的失效。从代码注释看,Google 也注意到了这个问题并计划修改,但是目前为止还没有看到修复代码上线。 

其次,Android 对于 Safe Area 的定义和我们预期的有一些出入,在 iOS 上,Safe Area 是指不会被系统组件、挖孔/刘海等遮挡的可视区域,到了 Android 上就变成了只规避挖孔/刘海区域,一旦把设备横屏,就会发现内容又“不争气”的跑到状态栏下边去了。最后,以上内容只针对原生 WebView 实现,对于 UC 的 U4 内核等三方内核不适用,从目前的调研结果来看,UC 内核不是通过上述方式支持 Safe Area 的。

四、一些适配建议

Android 端的 Safe Area 适配目前来看是困难重重,如果仍旧“执迷不悟”的想克服这个难题,下面是我目前考虑出来的两种方案:

  • 接管系统定义 Safe Area 的能力,替换成我们想要的值。从上面的分析过程我们也可以看出来,Android 端的 Safe Area 参数之所以不符合预期,主要是值的来源就不对,如果我们能够把 WindowInsets 里的值改成期望的值,那么后面的所有问题都迎刃而解了。下面是一个简单实现:

override fun onCreate(savedInstanceState: Bundle?) {  webView = findViewById(R.id.webview)  //这里先通过一定途径获取到由AwDisplayCutoutController设置的Listener,否则会被我们设置的Listener覆盖掉  val onApplyWindowInsetsListener = webView?.getOnApplyWindowInsetsListeners()?.get(0)  webView?.setOnApplyWindowInsetsListener { view, insets ->      val builder = DisplayCutout.Builder()      val originCutout = insets.displayCutout      val cutoutPath = originCutout?.cutoutPath      if (cutoutPath != null) {          builder.setCutoutPath(cutoutPath)      }      val systemBarsInsets: Insets = insets.getInsets(WindowInsets.Type.systemBars())      val imeInsets = insets.getInsets(WindowInsets.Type.ime())      val bottom = if (imeInsets.bottom > 0) {          0      } else {          systemBarsInsets.bottom + OFFSET      }      builder.setSafeInsets(Insets.of(          max(systemBarsInsets.left, originCutout?.safeInsetLeft ?: 0),          max(systemBarsInsets.top + OFFSET, originCutout?.safeInsetTop ?: 0),          max(systemBarsInsets.right, originCutout?.safeInsetRight ?: 0),          max(bottom, originCutout?.safeInsetBottom ?: 0)      ))      builder.setWaterfallInsets(originCutout?.waterfallInsets ?: Insets.NONE)      builder.setBoundingRectTop(originCutout?.boundingRectTop ?: Rect())      builder.setBoundingRectLeft(originCutout?.boundingRectLeft ?: Rect())      builder.setBoundingRectBottom(originCutout?.boundingRectBottom ?: Rect())      builder.setBoundingRectRight(originCutout?.boundingRectRight ?: Rect())      val newInsets = WindowInsets.Builder(insets).setDisplayCutout(builder.build()).build()      onApplyWindowInsetsListener?.onApplyWindowInsets(view, newInsets) ?: view.onApplyWindowInsets(newInsets)  }}

但是由于这个方式需要依赖系统能力,要考虑设备系统版本以及后续 API 发生变更的影响。

  • 和前端约定好,定义一套新的参数。Android 端一直面临碎片化的兼容适配,对于自研前端为主的场景,为了提升兼容性,可以自己定义一套参数来做适配。下面是一个简单实现:

override fun onCreate(savedInstanceState: Bundle?) {        super.onCreate(savedInstanceState)        val rootView = findViewById<View>(android.R.id.content)        window.decorView.getRootView().setOnApplyWindowInsetsListener { view, insets ->            updateInsets()            view.onApplyWindowInsets(insets)        }
        // 触发获取 WindowInsets        rootView.requestApplyInsets()}
private fun updateInsets() {    runOnUiThread {        WindowCompat.setDecorFitsSystemWindows(window, false)
        val windowInsets = ViewCompat.getRootWindowInsets(window.decorView)        val systemBarsInsets = windowInsets?.getInsets(WindowInsetsCompat.Type.systemBars()) ?: Insets.NONE        val imeInsets = windowInsets?.getInsets(WindowInsetsCompat.Type.ime()) ?: Insets.NONE
        val density = resources.displayMetrics.density
        setProperty("top", Math.round(systemBarsInsets.top / density) + offset)        setProperty("left", Math.round(systemBarsInsets.left / density))        if (imeInsets.bottom > 0) {            setProperty("bottom", 0)        } else {            setProperty("bottom", Math.round(systemBarsInsets.bottom / density) + offset)        }        setProperty("right", Math.round(systemBarsInsets.right / density))
        // To get the actual height of the keyboard, we need to subtract the height of the system bars from the height of the ime        // Source: https://stackoverflow.com/a/75328335/8634342        val imeHeight = imeInsets.bottom - systemBarsInsets.bottom
        // Set padding of decorview so the scroll view stays correct.        // Otherwise the content behind the keyboard cannot be viewed by the user.        window.decorView.setPadding(0, 0, 0, imeHeight)    }}
private fun resetProperties() {    setProperty("top", 0)    setProperty("left", 0)    setProperty("bottom", 0)    setProperty("right", 0)}
private fun setProperty(position: String, size: Int) {    runOnUiThread {        webView?.loadUrl("javascript:document.querySelector(':root')?.style.setProperty('--custom-safe-area-inset-" + position + "', 'max(env(safe-area-inset-" + position + "), " + size + "px)');void(0);")    }}
<!DOCTYPE html><html lang="zh"><head>    <meta charset="UTF-8">    <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">    <title>显示 Padding 值</title>    <style>        :root {            --custom-safe-area-inset-top: 0px;            --custom-safe-area-inset-bottom: 0px;            --custom-safe-area-inset-left: 0px;            --custom-safe-area-inset-right: 0px;        }        body {            margin: 0;            padding-top: var(--custom-safe-area-inset-top);            padding-bottom: var(--custom-safe-area-inset-bottom);            padding-left: var(--custom-safe-area-inset-left);            padding-right: var(--custom-safe-area-inset-right);            background-color: #f0f0f0;            font-family: Arial, sans-serif;        }        .padding-info {            background-color: #fff;            border: 1px solid #ddd;            height: 100vh;            padding: 10px;            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);        }</style></head><body><div class="padding-info" id="paddingDisplay">    <input type="text" id="inputField" name="inputField" placeholder="在这里输入..."></div></body></html>

自定义参数不用考虑 API 变更的影响,但是只能针对自研适配的前端页面生效。两种方式各有优劣,如果有更好的方式也欢迎探讨。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/886509.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

基础岛第3关:浦语提示词工程实践

模型部署 使用下面脚本测试模型 from huggingface_hub import login, snapshot_download import osos.environ[HF_ENDPOINT] https://hf-mirror.comlogin(token“your_access_token")models ["internlm/internlm2-chat-1_8b"]for model in models:try:snapsh…

【Linux】环境变量(初步认识环境变量)

文章目录 1. 环境变量1.1 基本概念 2. 认识常见环境变量2.1 PATH2.2 HOME2.3 SHELL2.4 PWD2.5 USER 3. 理解环境变量 1. 环境变量 在main函数的命令行参数中&#xff0c;有argc、argv、env三个参数。 argc&#xff1a;命令行参数的个数argc&#xff1a;存放每个参数的具体数值…

TOGAF框架在企业数字化转型中从理论到实践的全面应用指南

数字化转型的背景与意义 随着全球技术的快速发展&#xff0c;数字化已成为现代企业生存和发展的核心驱动力。企业数字化转型不仅意味着引入新技术&#xff0c;还要求在业务模式、组织架构和运营方式上进行深度变革。然而&#xff0c;数字化转型的实施通常面临诸多挑战&#xf…

vmvare虚拟机centos 忘记超级管理员密码怎么办?

vmvare虚拟机centos 忘记超级管理员密码怎么办?如何重置密码呢? 一、前置操作 重启vmvare虚拟机的过程中,长按住Shift键 选择第一个的时候,按下按键 e 进入编辑状态。 然后就会进入到类似这个界面中。 在下方界面 添加 init=/bin/sh,然后按下Ctrl+x进行保存退出。 init=/bi…

Unity开发绘画板——04.笔刷大小调节

笔刷大小调节 上面的代码中其实我们已经提供了笔刷大小的字段&#xff0c;即brushSize&#xff0c;现在只需要将该字段和界面中的Slider绑定即可&#xff0c;Slider值的范围我们设置为1~20 代码中只需要做如下改动&#xff1a; public Slider brushSizeSlider; //控制笔刷大…

【hot100-java】【寻找两个正序数组的中位数】

二分查找篇 如果使用之前的两个指针分别遍历再合并的话就已经超过时间复杂度了。。 class Solution {public double findMedianSortedArrays(int[] nums1, int[] nums2) {int mnums1.length;int nnums2.length;if(m>n){return findMedianSortedArrays(nums2,nums1);}int tot…

Web3Auth 如何工作?

Web3Auth 用作钱包基础设施&#xff0c;为去中心化应用程序 (dApp) 和区块链钱包提供增强的灵活性和安全性。在本文档中&#xff0c;我们将探索 Web3Auth 的功能&#xff0c;展示它如何为每个用户和应用程序生成唯一的加密密钥提供程序。 高级架构 Web3Auth SDK 完全存在于用…

Cpp::STL—string类的模拟实现(12)

文章目录 前言一、string类各函数接口总览二、默认构造函数string(const char* str "");string(const string& str);传统拷贝写法现代拷贝写法 string& operator(const string& str);传统赋值构造现代赋值构造 ~string(); 三、迭代器相关函数begin &…

JS基础练习|动态创建多个input,并且支持删除功能

效果图 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>动态生成输入框并保存数据</title>&…

誉天Linux云计算课程学什么?为什么保障就业?

一个IT工程师相当于干了哪些职业? 其中置顶回答生动而形象地描绘道&#xff1a; 一个IT工程师宛如一个超级多面手&#xff0c;相当于——加班狂程序员测试工程师实施工程师网络工程师电工装卸工搬运工超人。 此中酸甜苦辣咸&#xff0c;相信很多小伙伴们都深有体会。除了典…

【微服务】注册中心 - Eureka(day3)

CAP理论 P是分区容错性。简单来说&#xff0c;分区容错性表示分布式服务中一个节点挂掉了&#xff0c;并不影响其他节点对外提供服务。也就是一台服务器出错了&#xff0c;仍然可以对外进行响应&#xff0c;不会因为某一台服务器出错而导致所有的请求都无法响应。综上所述&…

uniapp修改uni-ui组件样式(对微信小程序/H5有效,vue3)

寻找要修改的样式 使用开发者工具找到具体要修改的class类名 修改 <style lang"scss">//.nav为上一级的class.nav::v-deep .uni-navbar--border {border-bottom-style: none !important;} </style>完整代码 <template><view><uni-na…

Kafka学习笔记(三)Kafka分区和副本机制、自定义分区、消费者指定分区

文章目录 前言7 分区和副本机制7.1 生产者分区写入策略7.1.1 轮询分区策略7.1.2 随机分区策略7.1.3 按key分区分配策略7.1.4 自定义分区策略7.1.4.1 实现Partitioner接口7.1.4.2 实现分区逻辑7.1.4.3 配置使用自定义分区器7.1.4.4 分区测试 7.2 消费者分区分配策略7.2.1 RangeA…

【华为HCIP实战课程三】动态路由OSPF的NBMA环境建立邻居及排错,网络工程师

一、NBMA环境下的OSPF邻居建立问题 上节我们介绍了NBMA环境下OSPF邻居建立需要手动指定邻居,因为NBMA环境是不支持广播/组播的 上一节AR1的配置: ospf 1 peer 10.1.1.4 //手动指定邻居的接口地址,而不是RID peer 10.1.1.5 area 0.0.0.0 手动指定OSPF邻居后抓包查看OSP…

C语言的内存结构

在电脑中C语言编译器也像其他软件一样占用一块内存空间。 为了更好的利用好这块内存&#xff0c;C语言将他们分为 在C语言中&#xff0c;变量定义的位置不一样&#xff0c;那么在内存中所处的位置也是不一样的。&#xff08;变量在函数内部是存储在栈里&#xff0c;而在函数外部…

SPI通信——FPGA学习笔记14

一、简介 SPI(Serial Periphera Interface&#xff0c;串行外围设备接口)通讯协议&#xff0c;是 Motorola 公司提出的一种同步串行接口技术&#xff0c;是一种高速、全双工、同步通信总线&#xff0c;在芯片中只占用四根管脚用来控制及数据传输&#xff0c;广泛用于 EEPROM、F…

基于STM32的智能家居灯光控制系统设计

引言 本项目将使用STM32微控制器实现一个智能家居灯光控制系统&#xff0c;能够通过按键、遥控器或无线模块远程控制家庭照明。该项目展示了如何结合STM32的外设功能&#xff0c;实现对灯光的智能化控制&#xff0c;提升家居生活的便利性和节能效果。 环境准备 1. 硬件设备 …

C--编译和链接见解

欢迎各位看官&#xff01;如果您觉得这篇文章对您有帮助的话 欢迎您分享给更多人哦 感谢大家的点赞收藏评论 感谢各位看官的支持&#xff01;&#xff01;&#xff01; 一&#xff1a;翻译环境和运行环境 在ANSIIC的任何一种实现中&#xff0c;存在两个不同的环境1&#xff0c;…

戴尔电脑怎么开启vt虚拟化_戴尔电脑新旧机型开启vt虚拟化教程

最近使用戴尔电脑的小伙伴们问我&#xff0c;戴尔电脑怎么开启vt虚拟。大多数可以在Bios中开启vt虚拟化技术&#xff0c;当CPU支持VT-x虚拟化技术&#xff0c;有些电脑会自动开启VT-x虚拟化技术功能。而大部分的电脑则需要在Bios Setup界面中&#xff0c;手动进行设置&#xff…

SpringCloud入门(九)Feign实战应用和性能优化

一、Feign实战应用 Feign的客户端与服务提供者的controller代码非常相似&#xff1a; 有没有一种办法简化这种重复的代码编写呢&#xff1f; 方式一&#xff1a;继承 优点&#xff1a; 简单。实现了代码共享。 缺点&#xff1a;服务提供方、服务消费方紧耦合。参数列表中的注解…