我正在制作一个应用程序,只是为了检验一些新的L API,我对FloatingActionButton
和Palette颜色生成器特别感兴趣。因此,我设置了全屏ImageView
显示HTC墙纸,然后使用提取其中一种颜色Palette
并将其设置为FAB的背景色。但是,这样做会从我的FAB中删除大纲,因此它不再是圆形的。
我想知道,如果可能的话,如何阻止调色板覆盖大纲。
调色板AsyncListener:
Palette.generateAsync(BitmapFactory.decodeResource(getResources(),R.drawable.wallpapers_07),
new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
PaletteItem item = palette.getLightVibrantColor();
ImageButton button = (ImageButton) findViewById(R.id.fab);
if (item != null) {
button.setBackgroundColor(item.getRgb());
}
}
});
int size = getResources().getDimensionPixelSize(R.dimen.fab_size);
Outline outline = new Outline();
outline.setOval(0, 0, size, size);
findViewById(R.id.fab).setOutline(outline);
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item>
<shape android:shape="oval">
<solid android:color="?android:colorAccent"/>
</shape>
</item>
您正在用颜色(ColorDrawable)替换背景可绘制对象(RippleDrawable)。而是要更改背景可绘制对象所包含的形状(GradientDrawable)的颜色。
尝试改为更改滤色器:
findViewById(R.id.fab).getBackgroundDrawable().setColorFilter(
new PorterDuffColorFilter(item.getRgb(), Mode.SRC_IN));
如果您经常更改颜色,则可以缓存颜色滤镜对象并使用setColor(int),然后使用findViewById(R.id.fab).invalidate()更新视图。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句