In android creating spinners - known as comboboxes or Drop-down list in other systems - is easy. However giving them a basic design is a little tricky.
In most application we dont want to add custom design to spinners, but at least we want thicker items in the list. With the default look, people will have trouble hitting the desired item.
The code, one may try at first, to fill a spinner with elements, will probably look like this:
There are situations where you have to use a Canvas. What do you do if you have more text than you can properly display?
The problem is, that if you want multiline text on canvas, with the drawText method, you would have to measure how much space a single line of text would take up, and also compare it to the width of the screen, and draw each line separately.
Read more to check my solution.
As we previously desribed in PreferenceActivity Basics a preferences screen with basic features can be done with minimal work, only using XML. Now we will inplement some functionality beyond the base ones, this will require some coding in addition to the XML definition.
We will display the actual value in each preferences summary field, like this:
The base XML will be the same as in the previous example, but we dont need to fill summary fields, they will be filled dinamically.
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
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:
ComponentName componentToDisable =
new ComponentName("com.helloandroid.apptodisable",