Android - Create app with pure Java and no XML?

Is it possible to avoid XML? Yes, with the exception of the manifest and perhaps some theme declarations (I'm not sure if there are public Java equivalents for everything we can set up via themes).

Is it a good idea? Heavens, no.

The point behind the resource system is to allow Android to transparently hand you the proper resources needed by the device at the present moment, based on both permanent device characteristics (e.g., screen density) and transient device characteristics (e.g., portrait vs. landscape orientation).

To avoid the resources, you will have to go through a bunch of if statements to determine which hunk of Java code to run, detecting all these things by hand. This gets significantly more complicated once you take into account changes in Android itself, as new configuration changes and values get added, making it difficult for you to support everything you need to in a backwards-compatible way.

Along the way, you will lose all tool support (drag-and-drop GUI building, MOTODEV Studio's string resource assistants, etc.), outside of plain Java editing and debugging.

You seem to be placing your own personal technical inclinations ahead of all other considerations. If this is some small personal project, that may be a fine attitude. If you are creating code to be developed and/or maintained by others over time, though, you need to factor in the needs of those other developers, and they may be much more open to XML than are you.


Take a look at this video, just posted by the android team: http://www.parleys.com/#st=5&id=2191&sl=8

It's all about layouts and includes how to layout apps using Java, not XML. However, you are warned that the android team wants you to use XML...


For the layouts you have two options

  1. Declare UI elements in XML. Android provides a straightforward XML vocabulary that corresponds to the View classes and subclasses, such as those for widgets and layouts.

  2. Instantiate layout elements at runtime. Your application can create View and ViewGroup objects (and manipulate their properties) programmatically.

So for the first question - yes - you can delete xml layout files (if you must).

I think you cannot get rid of the manifest.xml..Quoting:

Every application must have an AndroidManifest.xml file (with precisely that name) in its root directory.