android - 基于图像的亮/暗状态栏

标签 android android-glide android-statusbar

我的应用程序中有一个屏幕,可以在透明状态栏后面加载图像。有时这些图像足够轻,以至于状态栏图标和文本会在图像中丢失。
如何根据下方图像的颜色将状态栏设置为亮/暗?我试图保持状态栏完全透明而不添加背景。

最佳答案

您可以使用此解决方案根据您的背景更改状态栏颜色:

// Set the background and text colors of a toolbar given a
// bitmap image to match
public void setToolbarColor(Bitmap bitmap) {
    // Generate the palette and get the vibrant swatch
    // See the createPaletteSync() method
    // from the code snippet above
    Palette p = createPaletteSync(bitmap);
    Palette.Swatch vibrantSwatch = p.getVibrantSwatch();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

    // Load default colors
    int backgroundColor = ContextCompat.getColor(getContext(),
        R.color.default_title_background);
    int textColor = ContextCompat.getColor(getContext(),
        R.color.default_title_color);

    // Check that the Vibrant swatch is available
    if(vibrantSwatch != null){
        backgroundColor = vibrantSwatch.getRgb();
        textColor = vibrantSwatch.getTitleTextColor();
    }

    // Set the toolbar background and text colors
    toolbar.setBackgroundColor(backgroundColor);
        toolbar.setTitleTextColor(textColor);
}
现在,只需从您的背景生成位图,然后将其与此方法一起使用。
欲了解更多信息,请访问官方开发者网站 - Color palette API

关于android - 基于图像的亮/暗状态栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70850812/

相关文章:

java - Getter 从 Activity 类返回 null

java - 从 Glide 下载大图像时出现内存不足错误

android - Glide 。缓存到外部存储(SD 卡)

android - 透明状态栏android

android - 当 SystemUI 在 Android Boot 中加载时

Android handle 'search' 自定义键盘上的按钮按下

javascript - 使用新约束调用 getUserMedia 会导致黑屏 (MediaStream.ended=true)

安卓 : setActionView(null) doesn't remove view and width trouble on MenuItem with ActionView

android - 在状态和导航栏后面显示内容

java - 在服务器返回 base64 时使用 glide 加载图像