【问题标题】:Change Status Bar Colour in Chrome Custom Tabs更改 Chrome 自定义选项卡中的状态栏颜色
【发布时间】:2018-06-16 02:42:52
【问题描述】:

我正在使用 Chrome 自定义标签在我的应用中显示网页内容。显然,这样做的主要优点之一是能够更改选项卡中的 UI 颜色。但是,我需要将状态栏颜色更改为我提供的原色的较暗版本。

有没有办法做到这一点?

作为参考,这是我的代码。

CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor(getResources().getColor(R.color.colorPrimary));
builder.setSecondaryToolbarColor(getResources().getColor(R.color.colorPrimary));
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(MainActivity.this, Uri.parse(url));

您可能已经猜到了,我想将状态栏颜色更改为R.color.colorPrimary,而不是自动选择的颜色。

非常感谢任何帮助

【问题讨论】:

    标签: android chrome-custom-tabs


    【解决方案1】:

    目前,在使用自定义选项卡时,您无法更改状态栏颜色。您可以从CustomTabsIntent.Buildersource code 自行查看,看看您可以自定义什么或查看documentation

    我自己还没有尝试过,但是如果您的目标是 api >= 21 (Lollipop),我认为以下代码可以解决。

    @Override
    public void onStart() {
        super.onStart();
        setStatusBarColor(R.color.colorPrimaryDark);
    }
    
    private void setStatusBarColor(int colorId) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(ContextCompat.getColor(this, colorId));
    }
    
    private void showUrl(String url) {
        setStatusBarColor(R.color.colorPrimary);
        yourCustomTabsIntent.launchUrl(this, Uri.parse(url));
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-24
      • 2018-06-23
      • 1970-01-01
      • 2015-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多