Todos os produtos
Search
Central de documentação

Mobile Platform as a Service:Definir a cor da barra de navegação

Última atualização: Jun 28, 2026

Esta API define a cor da barra de título.

Como usar a API setTitleColor

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

Para usar a API setTitleColor, defina o parâmetro H5Param.LONG_TRANSPARENT_TITLE como always ou auto antes do carregamento da página. Exemplo: param.putString(H5Param.LONG_TRANSPARENT_TITLE,"auto");

Exemplo de código

<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>

Referência da API

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

Parâmetros de entrada

Propriedade

Tipo

Descrição

Obrigatório

Valor padrão

color

int

Valor da cor em decimal.

Sim

-