Jan 31, 2012

How to write Android Style and Themes ?


We all know that Android has Style and Theme feature, We know that it work like CSS in context of HTML/Web. but I feel it is the most unexplored feature of Android. Since last few days I am working on it and I have create two theme named ThemeBlue and ThemeGreen. (Check attached screenshot)

I figure out following pros and cons. 

Pros

1. We can avoid Image (PNG,Bitmap,etc..) I also reduce size of APK 
2. We don't require images for Multiple screen resolution.
3. Less Memory allocation compare to Images


Cons

1. Only four shapes supported (rectangle, ring, ovel, line). we can not create complex shapes using it.
2. Gradient isn't supports by Stroke.
3. layer-list has limited feature, layer-list isn't support to arrange layer in specific/relative position.
4. Shape does not support path.






Steps to create Themes 

Step 1 : Open your eclipse and create new Android Project
Step 2 : Right click on project name select New->Android XML File
Step 3 : Create themes.xml file in values folder
Step 4 : Create styles.xml file in values folder
Step 5 : Create colors.xml file in values folder
Step 6 : Set your theme in AndroidManifest.xml - It will apply theme in all Activities, you can set theme for single activity using "setTheme()" function.

Here is the file content

themes.xml



     
      


styles.xml


    
    
    
 
    
    
    
 
 
 
     
 
  
  
      
  
  
  
  
    
    
    
 
 
 
     
 
  


colors.xml


    #ffffff
    #000000
    #2f6699
    #449def
    #53933f
    #70c656



Download Code : Click Here
Click on File -> Download Original File





0 comments:

Post a Comment