gpt4 book ai didi

图像背景颜色匹配时,Android 工具栏菜单图标 "disappear"

转载 作者:行者123 更新时间:2023-11-30 01:58:03 25 4
gpt4 key购买 nike

看看这张图片

enter image description here

左上角是 Android 汉堡包菜单,但它是白色的。另外,右边是一个搜索放大镜,也是白色的。问题是背景是根据呈现的内容从服务器动态加载的。

是否可以对菜单图标进行着色或提升它们,以便在出现这种情况时出现?该背景图像实际上可以是任何颜色,这实际上取决于服务器的颜色。也许也可以在它们上使用 Palette 库?

编辑:到目前为止,我的解决方案基于@Steve 的回复:

private void loadBackdrop( String inetref ) {
Log.i( TAG, "loadBackdrop : inetref=" + inetref );

String bannerUrl = MainApplication.getInstance().getMasterBackendUrl() + "/Content/GetRecordingArtwork?Inetref=" + inetref + "&Type=banner&Height=256";
Log.i(TAG, "loadBackdrop : bannerUrl=" + bannerUrl);
final ImageView imageView = (ImageView) findViewById( R.id.backdrop );
final PaletteTransformation paletteTransformation = PaletteTransformation.getInstance();
Picasso.with( this )
.load( bannerUrl )
.fit().centerCrop()
.transform( paletteTransformation )
.into(imageView, new Callback.EmptyCallback() {

@Override
public void onSuccess() {

Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); // Ew!
Palette palette = PaletteTransformation.getPalette(bitmap);

try {

int inverseColor = getComplementaryColor(palette.getVibrantColor(R.color.white));
Log.i( TAG, "loadBackdrop : inverseColor=" + inverseColor + ", Color.WHITE=" + Color.WHITE + ", Color.BLACK=" + Color.BLACK + ", Color." + ( inverseColor > ( Color.BLACK / 2 ) ? "WHITE" : "BLACK" ) );

int color = ( inverseColor > ( Color.BLACK / 2 ) ? Color.WHITE : Color.BLACK );

collapsingToolbar.setCollapsedTitleTextColor( color );
collapsingToolbar.setExpandedTitleColor( color );

Drawable newSearchMenuItem = mSearchMenuItem.getIcon();
newSearchMenuItem.mutate().setColorFilter( color, PorterDuff.Mode.SRC_IN );
mSearchMenuItem.setIcon( newSearchMenuItem );

Drawable newUpMenuItem = getResources().getDrawable( R.drawable.ic_arrow_back_white_24dp );
newUpMenuItem.mutate().setColorFilter( color, PorterDuff.Mode.SRC_IN );
getSupportActionBar().setHomeAsUpIndicator( newUpMenuItem );

} catch( Exception e ) {
Log.e( TAG, "error decoding palette from imageView", e );
}
}

@Override
public void onError() {

}

});

}

public static int getComplementaryColor( int colorToInvert ) {

float[] hsv = new float[ 3 ];
Color.RGBToHSV( Color.red( colorToInvert ), Color.green( colorToInvert ), Color.blue( colorToInvert ), hsv );

hsv[ 0 ] = ( hsv[ 0 ] + 180 ) % 360;

return Color.HSVToColor( hsv );
}

最佳答案

你应该看看this .基本上,您可以做的是为您想要着色的图标创建具有不同着色 .png 文件的自定义主题,然后根据给定的背景颜色在代码中设置这些主题;或者您可以执行与该网站上显示的内容类似的操作。希望这对您有所帮助!

编辑:你可以根据背景颜色做这样的事情:

MenuItem YOUR_MENU_ITEM = menu.findItem(R.id.YOUR_MENU_ITEM_ID);
Drawable NEW_ICON = (Drawable)YOUR_MENU_ITEM.getIcon();
NEW_ICON.mutate().setColorFilter(Color.argb(255, 200, 200, 200),PorterDuff.Mode.SRC_IN);
YOUR_MENU_ITEM.setIcon(NEW_ICON);

这会将图标染成灰色,但您可以根据需要更改滤色器的值。

What you could do to solve the issue of dynamically loaded backgrounds is to use a case or nested if statement to check background of server, and then provide a color filter option for the more common colors (red, yellow, blue, etc.) generally black/white will show up on most backgrounds so you can use those as the default value.

编辑:进行颜色匹配:

So you could do something like this which would just reverse the given color to its compliment..otherwise let me know if thats not what you are looking for

关于图像背景颜色匹配时,Android 工具栏菜单图标 "disappear",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31906627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com