Monday, 27 January 2014

Android styles

1) Fetch the theme from manifest file
     getResources().getResourceEntryName(getApplicationInfo().theme)
2)Set the theme globally in the App based on the condition
           if(getResources().getResourceEntryName(getApplicationInfo().theme).equalsIgnoreCase("Theme.One"))
        {
           int brandStyle = R.style.settingsThemeAppone;
             setBrandStyle(brandStyle);
         }
        else
        {
           int brandStyle = R.style.settingsThemeApptwo;
            setBrandStyle(brandStyle);
        }

3)Declare in styles.xml the following
   <style name="settingsThemeAppone">
      <item name="attr/settingslist_home">@drawable/icon_settingslistone_home</item>
      <item name="attr/settingslist_aboutus">@drawable/icon_settingslistone_about</item>
      <item name="attr/settingslist_click">@drawable/icon_settingslistone_click</item>
      </style>

    <style name="settingsThemeApptwo">
  <item name="attr/settingslist_home">@drawable/icon_settingslisttwo_home</item>
  <item name="attr/settingslist_aboutus">@drawable/icon_settingslisttwo_about</item>
  <item name="attr/settingslist_click">@drawable/icon_settingslisttwo_click</item>
  </style>

 <style name="colorThemeAppone">
           <item name="attr/active_color">@color/colorAppone</item>
           <item name="attr/inactive_color">@color/viewApptwo</item>
                    
        </style>

<style name="colorThemeApptwo">
           <item name="attr/active_color">@color/colorApptwo</item>
           <item name="attr/inactive_color">@color/viewApptwo</item>
                  </style>


4)Declare in attr.xml the following

<declare-styleable name="settingsTheme" >
         
            <attr name="settingslist_home" format="reference" />
            <attr name="settingslist_aboutus" format="reference" />
            <attr name="settingslist_click" format="reference" />
                
         
          </declare-styleable>

 <declare-styleable name="colorTheme" >
         
            <attr name="active_color" format="color" />
            <attr name="inactive_color" format="color" />
                
          </declare-styleable>
5) Access and place the drawables

    TypedArray a = getContext().getTheme().obtainStyledAttributes(getDataModel().getBrandStyle(), new int[] {R.attr.settingslist_home});    
                int attributeResourceId = a.getResourceId(0, 0);
                return attributeResourceId;

TypedArray templevels = getContext().getTheme().obtainStyledAttributes(getDataModel().getBrandStyle(), new int[] {R.attr.settingslist_aboutus});    
                int attributeResourceIdtemplevels = templevels.getResourceId(0, 1);
                return attributeResourceIdtemplevels;   

6)Accessing colors

TypedArray a = getContext().getTheme().obtainStyledAttributes(
                dataModel.getBrandStyleColor(),
                new int[] { R.attr.inactive_color });
  
     
        int highlight_color = a.getColor(a.getIndex(0), 0);

    TypedArray a = getContext().getTheme().obtainStyledAttributes(
                dataModel.getBrandStyleColor(),
                new int[] { R.attr.active_color });
   

       
        int highlight_color = a.getColor(a.getIndex(0), 0);
       

       

No comments:

Post a Comment

Pass a HashMap from Angular Client to Spring boot API

This example is for the case where fileData is very huge and in json format   let map = new Map<string, string>()      map.set(this.ge...