在我的在实际开发中,动态修改图标的功能不在应用首页,一般都会在设置或者界面样式修改这样比较深层次的界面中,如果使用上篇博文,便会导致切换图标后,我的手机桌面出现两个不同图标的同款应用,卸载一个后另一个跟着被卸载,显然不是我想要的功能。
主要是MainActivity.java:
//四个按钮的点击事件
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.LogoOneImage:
setPrimitiveIcon();
break;
case R.id.LogoTwoImage:
setAdvancedIcon();
break;
case R.id.LogoThreeImage:
setSteadyBlueIcon();
break;
case R.id.LogoFourImage:
setDarkNightIcon();
break;
default:
break;
}
}
//设置 "一号"图标
private void setPrimitiveIcon() {
PackageManager packageManager = getPackageManager();
packageManager.setComponentEnabledSetting(new ComponentName(this, getPackageName() +
".SteadyBlueActivity"), PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
packageManager.setComponentEnabledSetting(new ComponentName(this, getPackageName() +
".DarkNightActivity"), PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
packageManager.setComponentEnabledSetting(new ComponentName(this, getPackageName() +
".RoundActivity"), PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
packageManager.setComponentEnabledSetting(new ComponentName(this, getPackageName(