How to get favorites star

后端 未结 3 2178
鱼传尺愫
鱼传尺愫 2021-02-09 18:40

I would like to add a favorites star like the one in the contacts list on android. Is there any way we can get that star or will I have to write my own? I can\'t seem to find

相关标签:
3条回答
  • 2021-02-09 19:10

    @android:drawable/btn_star (this one turns yellow)

    @android:drawable/star_off

    and variations on those (big, on, off)

    0 讨论(0)
  • 2021-02-09 19:10

    Some standard android images are available from the android sdk, which you can either browse on your computer on online here. (As CommonsWare said).

    I also find this website super handy, as it shows me what each image looks like and tells me the name of the image so I can find it in the android sdk.

    0 讨论(0)
  • 2021-02-09 19:16

    The source code to the Contacts application is available online, since Android is open source.

    Some poking around in there will lead you to the contact_header.xml file, found in your SDK installation. It indicates that the star is implemented via a CheckBox:

    <CheckBox
            android:id="@+id/star"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:visibility="gone"
            android:contentDescription="@string/description_star"
            style="?android:attr/starStyle" />
    

    That, in turn, routes you to an entry in a theme:

    <item name="starStyle">@android:style/Widget.CompoundButton.Star</item>
    

    which in turn resolves to:

    <style name="Widget.CompoundButton.Star">
        <item name="android:background">@android:drawable/btn_star_label_background</item>
        <item name="android:button">@android:drawable/btn_star</item>
    </style>
    

    So, use those images with a CheckBox, and you should get the same behavior. Those images are also available in your SDK installation.

    0 讨论(0)
提交回复
热议问题