java - 如何使用 Imageview 颜色更改应用栏颜色?
问题描述
我有一个通知日志应用程序,如何使用相同颜色的应用程序图标更改应用程序栏颜色。
例如,我想从图标图像颜色更改应用栏颜色
我得到这样的图标
ImageView icon = findViewById(R.id.icon);
icon.setImageDrawable(Util.getAppIconFromPackage(this, packageName));
那么如何从图像视图中获取颜色并将其更改为应用栏颜色
解决方案
SOLVED !!
Add This Gradle
implementation 'com.android.support:palette-v7:23.1.1'
And Add This Code In Activity
private void geticoncolor() {
ImageView icon = findViewById(R.id.icon);
icon.setImageDrawable(Util.getAppIconFromPackage(this, packageName));
//Bitmap bitmap = BitmapFactory.decodeResource(getResources(), geticoncolor());
Bitmap bitmap3 = ((BitmapDrawable)icon.getDrawable()).getBitmap();
BitmapDrawable drawable = (BitmapDrawable) icon.getDrawable();
Bitmap bitmap2 = drawable.getBitmap();
Palette.from(bitmap3).generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
//work with the palette here
int defaultValue = 0x000000;
int vibrant = palette.getVibrantColor(defaultValue);
int vibrantLight = palette.getLightVibrantColor(defaultValue);
int vibrantDark = palette.getDarkVibrantColor(defaultValue);
int muted = palette.getMutedColor(defaultValue);
int mutedLight = palette.getLightMutedColor(defaultValue);
int mutedDark = palette.getDarkMutedColor(defaultValue);
ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(vibrant));
// actionBar.setTitle(Html.fromHtml("<font color='#000099'>Hello World</font>"));
// Toast.makeText(DetailsActivity.this, ""+vibrant+vibrantDark+mutedLight+mutedDark, Toast.LENGTH_SHORT).show();
/*vibrantView.setBackgroundColor(vibrant);
vibrantLightView.setBackgroundColor(vibrantLight);
vibrantDarkView.setBackgroundColor(vibrantDark);
mutedView.setBackgroundColor(muted);
mutedLightView.setBackgroundColor(mutedLight);
mutedDarkView.setBackgroundColor(mutedDark);*/
}
});
}
推荐阅读
- reporting-services - 有没有办法在报表中为 Tablix 设置固定位置?
- git - 在 GitLab 中使用基于主干的方法添加审查选项
- database - Update by query with a clause in ElasticSearch
- python-3.x - Most "pythonic" way of populating a nested indexed list from a flat list
- git - Windows 上的 sh shell 脚本导致错误:/dev/tty: No such device or address
- charts - How to hide Google Charts hours from hAxis
- python-3.x - 我怎么知道今天是否是由于改变民用当地时间的一天,例如标准python和pandas时间戳中的夏令时?
- ms-access - 我想从 MS Access Query 中的交易表中获取期初和期末余额
- excel - 如何输入结果 % 以正确更改初始值?
- javascript - Nativescript JS 将 URLSearchParams 发送到 POST 请求中