How to create a Widget.Holo.Spinner-style widget in v7

前端 未结 2 1948
夕颜
夕颜 2021-01-04 11:16

I have a Button that I want to style like a Holo-style spinner, i.e. underlined with a triangle in the bottom right corner - the built-in contacts app for examp

2条回答
  •  情书的邮戳
    2021-01-04 12:07

    User "ozi" got me there, unfortunately his answer got deleted because it was just a link.

    The trick is to use a custom attribute and override it with a v11-specific section. Here's the basic setup if you use themes:

    In values/attr.xml:

    
        
    
    

    You create your Spinner-Button like this:

    And here's the key: You have different values in the theme depending on whether or not you have v11:

    In values/themes.xml:

    
    

    In values-v11/themes.xml:

    
    

    If you don't use themes, your setup is almost identical - you just use styles.xml, create a specific style for your button, and use that.

    In pre-v11, this will create an old-style spinner, but that's actually good - a v11 spinner would look out of place in pre-v11 environment.

提交回复
热议问题