Converting XML properties to tags, and back again
If you do any amount of layout or styling on Android, you'll quickly find yourself copying blocks of XML tags back and forth between layout files and style.xml
resources. It's the difference between the XML property android:layout_width="match_parent"
and its tag counterpart, <item name="android:layout_width">match_parent</item>
.
The property format is used in layout elements in the /res/layout/
directory.
The <item>
tag format is used in /res/values/styles.xml
and its version-numbered buddies such as styles-v21.xml
.
To use it, open up the file and replace the value in the triple """
quotes of the input
variable with a block of your favorite XML properties (or tags).
$ vim android_xml_converter.py
If you give it a block of properties of the android:tag_name
kind, it'll print it back in <item>
tag format. If you give it a block of <item>
tags, you'll get a block of android:tag_name
properties.
Then, to run it:
$ chmod +x android_xml_converter.py
$ ./android_xml_converter.py
Ahhh.