我的应用程序中有一个开关。如果开关是on
我想设置一个不同的图标。如果开关是off
我必须设置其他图标。
我正在尝试这样
tButton.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if (isChecked)
{
tvStateofToggleButton.setText("ON");
getPackageManager().setComponentEnabledSetting(
new ComponentName("com.samir", "com.samir.MainActivity-Red"),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
} else
{
tvStateofToggleButton.setText("OFF");
getPackageManager().setComponentEnabledSetting(
new ComponentName("com.samir", "com.samir.MainActivity-Blue"),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
}
}
});
清单是
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.samir"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:launchMode="singleTask" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity-alias
android:name=".MainActivity-Red"
android:enabled="false"
android:icon="@drawable/red"
android:label="@string/app_name"
android:targetActivity=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity-alias
android:name=".MainActivity-Blue"
android:enabled="false"
android:icon="@drawable/blue"
android:label="@string/app_name"
android:targetActivity=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
</application>
</manifest>
控制台显示如下
[2013-11-09 13:03:40 - Android Switch Button] ActivityManager: Error type 3
[2013-11-09 13:03:40 - Android Switch Button] ActivityManager: Error: Activity class {com.samir/com.samir.MainActivity-Red} does not exist.
有人可以建议我正确的方法吗