Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guide for custom UI controls

Tags:

android

I want to develop an android application, but i dont want to use the default controls(buttons, checkboxes, radio buttons, etc.,). Is there any way to customize those controls to make it appear nicer. If so some tutorial or guide will help me a lot. Thanks....

like image 819
Ashok Kumar M Avatar asked Jun 18 '10 07:06

Ashok Kumar M


1 Answers

If you want to create completely new UI elements, you should read the developer guide topic on creating custom components/views.

If, on the other hand, you simply want to change the appearance of existing UI elements, below is a non-exhaustive list of things you'll need to do. This assumes you're familiar with the Android resources framework and layout system.

  • First, see how these are implemented in the Android source code (AOSP, GitHub's mirror). All of the code you're interested in is in the frameworks/base.git project (quick links: resources, Java sources)

  • For each type of UI element, create Nine Patch PNG drawables for each of the UI states (default, disabled, pressed, focused, etc.) and for each relevant density (e.g. medium, high , and extra-high densities). These PNGs should be in your res/drawable-mdpi/, res/drawable-hdpi/, and res/drawable-xhdpi/ directories.

  • For each type of UI element, create a state list XML drawable (<selector>), which will be in your res/drawable/ directory. The state list drawable for the default Android push button can be found here.

  • Set your button/textbox/etc.'s android:background attribute to the state list drawable name. For example, the attribute value should be @drawable/mybutton if your state list drawable is res/drawable/mybutton.xml.

    Note: You can use themes to reduce redundancy (i.e. keep them DRY) in your XML files.

like image 82
Roman Nurik Avatar answered Sep 25 '22 19:09

Roman Nurik