Removing an app icon from launcher

SDK Version: 

Creating an application that does not appear among the launchable applications with an icon is easy.
Just do not put a launcher activity into AndroidManifest.xml

  1. <intent-filter>
  2.   <action android:name="android.intent.action.MAIN" />
  3.   <category android:name="android.intent.category.LAUNCHER" />
  4. </intent-filter>

Removing an application icon after installation programatically is a bit more tricky.
You can not disable the icon itself, but you can disable one component of an application. So disabling the applications launcher activity will result its icon to be removed from launcher.

The code to do this is simple:

  1. ComponentName componentToDisable =
  2.   new ComponentName("com.helloandroid.apptodisable",
  3.   "com.helloandroid.apptodisable.LauncherActivity");
  5. getPackageManager().setComponentEnabledSetting(
  6.   componentToDisable,

How to disable a button on an appwidget?

SDK Version: 

Would you like to disable a button on an appwidget?
As far as I know it can not be done, since the appwiget UI manipulation is limited by the methods of the RemoteViews class.

But if you insist to do that there is a way to make it look like the button were disabled!

RemoteViews can't manipulate a buttons enabled/disabled state, but it can modify its visibility. So the trick is to have two buttons, the real one, and an other which is designed to look like the real one in disabled state, and change witch one is visible.

Lets see a simple example:
We want to have two buttons on the widget, a stop and a start button in order to stop and start some kind of functionality. Once we have started it, we can not start it agin, until we stopped it and vica versa, so we want to disable the button which can not be used right now.

The XML definition of the buttons can be like this:

  1. <Button android:id="@+id/startbutton" android:text="Start" android:visibility="visible" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
  2. <Button android:id="@+id/startbutton_disabled" android:text="Start" android:clickable="false" android:textColor="#999999" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>

Syndicate content