我想添加一个最喜欢的星星,就像 Android 上的联系人列表中的星星一样。我们有什么办法可以获得那颗星星,还是我必须自己写?除了选项菜单图标之外,我似乎找不到任何来自 android 的标准 GUI 元素。还有其他我没找到的吗?
看看乔治·安德森旁边的那个。当你点击它时,它会变成黄色。
(source: mail2web.com https://mail2web.com/services-data/images/android/contacts-on-android.jpg)
联系人应用程序的源代码是在线提供 http://android.git.kernel.org/?p=platform/packages/apps/Contacts.git;a=tree,因为 Android 是开源的。
在那里闲逛一些会引导你到contact_header.xml
文件,在您的 SDK 安装中找到。它表明星号是通过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" />
反过来,这会将您路由到主题中的条目:
<item name="starStyle">@android:style/Widget.CompoundButton.Star</item>
这又决定:
<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>
因此,使用这些图像CheckBox
,并且您应该得到相同的行为。这些图像也可以在您的 SDK 安装中找到。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)