android首选项水平分隔线在自定义首选项? [英] android preference horizontal divider in custom preference?

查看:92
本文介绍了android首选项水平分隔线在自定义首选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了自己的自定义首选项对象,以扩展首选项.我之所以创建它们是因为这些自定义数据类型没有首选项.

I've created my own custom preference objects that extend Preference. I've only created them because there are no Preferences for these custom data types.

一切正常,但是我的自定义首选项外观不同,因为它们缺少系统首选项对象所具有的水平分隔线.我一直在寻找创建水平分隔线的代码,但是找不到在哪里完成.

Everything is working, but my custom preferences don't have the same appearance because they are missing the horizontal divider that the system preference objects have. I've looked for the code that is creating the horizontal divider, but I can't find where it is done.

内置的分隔器不只是一根细条.有点渐变.我想这可能在布局文件中,但是找不到系统首选项的布局.

The built in divider isn't just a thin bar. There is a bit of a gradient to it. I'm thinking that this may be in a layout file, but I can't find the layouts for the system preferences.

有人知道如何实现吗?

推荐答案

非常古老的帖子,但对于那些偶然发现的人来说.不确定OP是否在询问如何更改分隔线或分隔线图像来自何处.所以我会同时解决.

Very old post, but to those who stumble upon this. Wasn't sure if the OP was asking how to change the divider or where the divider images come from. So I'll address both.

方法
Preferences使用ListView填充所有单个首选项.这意味着您可以使用ListView中的.setDivider()方法更改分频器. PreferenceActivity将已经为您提供getListView()方法.但是对于PreferenceFragments,只需使用android.R.id.list ID即可找到它.

How
Preferences uses a ListView for populating all the individual preferences. That means you can change the divider by using the .setDivider() method from ListView. A PreferenceActivity will already have the getListView() method for you. However for PreferenceFragments just use the android.R.id.list ID to find it.

如果您不想通过代码更改分隔线,则始终可以通过覆盖listDivider属性来使用主题.例如:

If you don't want to change the divider through code, you can always use a theme by overriding the listDivider attribute. Eg:

<item name="android:listDivider">@drawable/custom_divider</item>

请注意,这将更改应用程序中每个ListView的分隔线.

Note, that will change the divider for EVERY ListView in your app.

位置
使用的listDivider drawable取决于激活的Android主题.您可以在以下位置的已安装Android SDK中找到所有这些图像:
[Android SDK]/平台/[API]/data/res/drawable- [DPI]/

Where
The listDivider drawable used depends on what Android theme is activated. You'll find all these images in the installed Android SDK at this location:
[Android SDK]/platforms/[API]/data/res/drawable-[DPI]/

只需搜索`* divider_horizo​​ntal *`,您就会发现很多内容.它们是九个补丁,并非全部都是纯色.

Just do a search for `*divider_horizontal*`, and you'll turn up quite a few. They are nine-patched and not all of them are solid colors.

这篇关于android首选项水平分隔线在自定义首选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆