当 CheckboxPreference 摘要字段不够长时,显示首选项屏幕的额外信息?
我有一个屏幕,您可以在其中启用/禁用我的 Android 应用程序的模块。
为此,我使用了 CheckboxPreference 屏幕。这一切都很好,但如果添加的描述超过 2 行,摘要字段就会被截断。
假设每个模块有 4-5 行可用的描述,我想在帮助器窗口中显示它。
我尝试将单击事件绑定到 CheckboxPreference,但该事件会针对整行触发,因此不仅在单击复选框时,而且无论您在何处单击该行,复选框都会切换。
所以现在我想知道这个问题是否可以解决。因此,如果用户需要更多信息,只需点击文本,助手就会打开,如果想要切换设置,则点击复选框。
你会怎么做?如果其他想法可行的话,我也愿意接受。
I have a screen where you can enable/disable modules for my Android application.
For this I use a CheckboxPreference screen. This is all good, but the summary field gets cut off if longer descriptions are added than 2 lines.
Suppose I have 4-5 lines of description available for each module, I would like to display this in a helper window.
I tried to bind a click event to the CheckboxPreference, but that fires for the whole line, so not only when the checkbox is clicked, and more, wherever you click on the line the checkbox is toggled.
So now I am wondering if this can be fixed. So if the user needs more info, just taps the text and the helper opens up, and if want to toggle the settings it taps the checkbox.
How would you do it? I am open to other ideas too, if they do work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您也许可以创建自己的
CheckboxPreference
子类,为您提供更多空间。You might be able to create your own subclass of
CheckboxPreference
that gives you more room.我找到了一个更适合我的情况的替代解决方案,因为我需要针对不同类型的首选项(而不仅仅是 CheckboxPreferences)提供更长的摘要。
data/res/layout/preference.xml
从 SDK 复制到我的应用中的res/layout/preference_long_summary.xml
。 (我从 API 级别 7 中选择了一个,因为它似乎也适用于更高级别)@+android:id/summary
TextView 中删除了android:maxLines
属性android:layout="@layout/preference_long_summary" 进行更长摘要的首选项
I found an alternative solution that fits better in my case since I needed longer summaries for different types of preferences, not only CheckboxPreferences.
data/res/layout/preference.xml
from the SDK tores/layout/preference_long_summary.xml
in my app. (I took the one from API level 7, since it seems to work also for higher levels)android:maxLines
attribute from the@+android:id/summary
TextViewandroid:layout="@layout/preference_long_summary"
嗯今天也遇到了同样的问题。
我的替代解决方案是只允许在摘要中显示更多文本。
只需创建您自己的 CheckBoxPreference 子类,如下所示:
然后在您的 PreferenceScreen 中(我假设您使用 xml 来设置 Preference 布局 - 不确定它是否可以完全以编程方式实现)只需替换旧的
使用您的新实现,如似乎对我来说工作得很好,尽管我不确定关于findViewById(android.R.id.summary),因为在parentClass中使用了com.android.internal.R.id.summary,这似乎无法从Java内部直接访问?希望这不仅仅是巧合:)
Hmn had the same problem today.
My alternative solution is to just allow to display more Text within the summary.
Just create your own subclass of CheckBoxPreference that looks something like this:
Then within your PreferenceScreen (i assume you use xml to set up the Preference layout - not sure if its even possible completely programmatically) just replace the old
<CheckBoxPreference.../>
with your new implementation like<com.example.whatever.CheckBoxPreferenceWithLongSummary ... />
Seems to work just fine for me, altough i'm not sure about the findViewById(android.R.id.summary) because in the parentClass com.android.internal.R.id.summary is used which seems to be not directly accessible from within Java? Hope its not just an coincidence :)