注:更新版本时。需换为默认的才可以更新apk
android:enabled="true"为默认
1、准备资源
(1)logo和名称资源
<string name="app_name">httpheader</string>
<string name="app_name1">第二名</string>
<string name="app_name2">第3名</string>
(2)配置组件资源
<activity-aliasandroid:name=".MainActivity0"android:enabled="true"android:icon="@mipmap/ic_1111"android:label="@string/app_name1"android:targetActivity=".MainActivity"><intent-filter><action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER"/></intent-filter>
</activity-alias><activity-aliasandroid:name=".MainActivity1"android:enabled="false"android:icon="@mipmap/ic_1212"android:label="@string/app_name2"android:targetActivity=".MainActivity"><intent-filter><action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER"/></intent-filter>
</activity-alias>
MainActivity需要添加属性:android:enabled="false"
2、初始化包管理类和多个组件
private ComponentName componentName1;
private ComponentName componentName2;
private PackageManager mPackageManager;
@Override
protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);setListener(this);//获取到包管理类实例mPackageManager = getPackageManager();componentName1 = new ComponentName(getBaseContext(), "com.tianxin.httpheader.MainActivity0");componentName2 = new ComponentName(getBaseContext(), "com.tianxin.httpheader.MainActivity1");
上面是 包名.配置组件名称
3、主要切换logo方法:
/*** 切换双11logo* @param*/
public void jump01() {enableComponent(componentName1);disableComponent(componentName2);
}
public void jump02() {enableComponent(componentName2);disableComponent(componentName1);
}/*** 启动组件* @param componentName 组件名*/
private void enableComponent(ComponentName componentName) {//此方法用以启用和禁用组件,会覆盖Androidmanifest文件下定义的属性mPackageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
}/*** 禁用组件* @param componentName 组件名*/
private void disableComponent(ComponentName componentName) {mPackageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
在线回复bug:QQ1085220040