All Products
Search
Document Center

Mobile Platform as a Service:Set navigation bar color

Last Updated:Jan 26, 2026

This API sets the color of the title bar.

How to use the setTitleColor API

AlipayJSBridge.call("setTitleColor", {
  color: 16775138,
  reset: false // Optional. Specifies whether to reset the title color to the default. Default: false.
});
Note

To use the setTitleColor API, set the H5Param.LONG_TRANSPARENT_TITLE parameter to `always` or `auto` before the page loads. For example: param.putString(H5Param.LONG_TRANSPARENT_TITLE,"auto");

Code example

<div style="padding-top:80px;">
  <a href="javascript:void(0)" class="btn title">Set navigation bar background color</a>
  <a href="javascript:void(0)" class="btn reset">Reset navigation bar background color</a>
  <a href="javascript:void(0)" class="btn pushWindow">Open a new window with a transparent navigation bar</a>
  <a href="javascript:void(0)" class="btn resetTransparent">Reset to a transparent navigation bar</a>
</div>

<script>
function ready(callback) {
  // If jsbridge is already injected, call it directly.
  if (window.AlipayJSBridge) {
    callback && callback();
  } else {
    // If not, listen for the injection event.
    document.addEventListener('AlipayJSBridgeReady', callback, false);
  }
}
ready(function(){
  document.querySelector('.title').addEventListener('click', function() {
    AlipayJSBridge.call("setTitleColor", {
      color: parseInt('108ee9', 16),
      reset: false // Optional. Specifies whether to reset the title color to the default. Default: false.
    });
  });

  document.querySelector('.reset').addEventListener('click', function() {
    AlipayJSBridge.call("setTitleColor",{
      color: 16775138,
      reset: true
    });
  });

  document.querySelector('.pushWindow').addEventListener('click', function() {
    AlipayJSBridge.call("pushWindow", {
      url: location.pathname + '?__webview_options__=transparentTitle%3Dalways'
    });
  });

  document.querySelector('.resetTransparent').addEventListener('click', function() {
    AlipayJSBridge.call("setTitleColor", {
      color: 16775138,
      resetTransparent: true
    });
  });
});
</script>

API reference

AlipayJSBridge.call('setTitleColor', {
  color: 16775138,
  reset: false,
  resetTransparent: false
}, fn)

Input parameters

Property

Type

Description

Required

Default value

color

int

The color value in decimal.

Yes

-