Use different icons with different Android SDK versions

前端 未结 2 1117
抹茶落季
抹茶落季 2021-01-31 11:39

I have icons for my Android menu. On Android 3+ I\'m using a black ActionBar so the icons are white. However, on Android 2.x the menu is inherently white which means the icons a

2条回答
  •  难免孤独
    2021-01-31 12:27

    You can Select a theme based on platform version, as outlined in the Styles and Themes dev guide. Define a style in your res/values/styles.xml like this:

    
    

    Then in a res/values-v11/ folder, select your theme (probably Holo, if you're dark)

    
    

    Then add icons to that style. For instance, here's a snippet from the styles.xml file from the HoneycombGallery sample application.

    
    

    The bottom 3 elements are all icons in the drawable directories. You'll still need at least one folder per resolution-specific set of icons, but you can combine the light & dark icons into the same folder, but you won't have to have different folders of icons for each platform version. Also, you'll need to list them as references in the values/attrs.xml file, like this:

    
      
        
        
        
        
      
    
    

    At which point you'll be able to refer to them within your layout XML using the "?attr/NameOfYourDrawable" dereference, like this:

    
    

提交回复
热议问题