- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在制作一个有一些设置的应用程序,我想使用内置的 PreferenceActivity 或 PreferenceFragment 来完成这项工作
有些首选项的标题很长,我无法缩短,而且我认为如果我对应用程序进行本地化(翻译成多种语言),我将面临同样的问题(例如德语,它有很长的词,有时)。
在这种情况下,您得到的只是文本的开头,然后是文本结尾的“...”(或更少的点,顺便说一句,这没有多大意义)。
例子:
我知道 PreferenceActivity 是从 ListActivity 扩展而来的,所以我可以将其适配器更改为我想要的任何内容,但这会破坏它的工作方式。
我也知道我可以从每种类型的首选项类进行扩展,使用“onCreateView”方法来引用创建的 View ,然后访问它的 subview ,但这很奇怪,不是吗?我的意思是,这几乎就像假设它永远不会改变它的外观一样。
编辑:这是我尝试过的示例代码:
从每个偏好类中扩展,并在每个偏好类中使用:
...
@Override
protected View onCreateView(final ViewGroup parent)
{
final View view=super.onCreateView(parent);
ViewUtil.handlePreferenceTitleTextView(view);
return view;
}
...
//ViewUtil.java :
private void handlePreferenceTitleTextView(final View v)
{
final TextView titleTextView=(TextView)v.findViewById(android.R.id.title);
if(titleTextView!=null)
titleTextView.setSingleLine(false);
}
它有效,但我认为不推荐这样做,因为 Google 可能会改变偏好 View 的工作方式。
如何在 Android 上处理首选项标题中的长文本?
是否可以让它有一个椭圆大小/选取框(这样它就会有一个动画来显示所有内容)?或者也许自动调整字体大小?或者将其设置为自动换行?或者允许用户滚动阅读其余文本的水平 ScrollView ?
是否有关于如何处理此类情况的约定?也许长按以显示 toast /对话框以查看整个文本?
最佳答案
这是我针对 SwitchPreference
的特定情况和一般偏好的问题的解决方案。
首先,我应该注意到,对于 14 之前的 API 级别,首选项标题似乎默认是多行的 - 至少我没有看到 Android 2.3.3 中的长标题有任何问题。在较新版本的 Android 中,此行为已更改为强制单行标题。
解决方法是稍微调整 SwitchPreference
或任何其他类型的首选项布局。
在首选项屏幕文件中添加所需首选项的 android:layout
属性,例如:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/prefs_category">
<SwitchPreference
android:key="keyOfThePreference"
android:title="@string/pref_title"
android:switchTextOn="@string/pref_on"
android:switchTextOff="@string/pref_off"
android:summaryOn="@string/pref_enabled"
android:summaryOff="@string/pref_disabled"
android:layout="@layout/preference_multiline"
/>
...
接下来,为 preference_multiline.xml
提供替代布局。我使用了标准 preference.xml
的修改版本:
<?xml version="1.0" encoding="utf-8"?>
<!-- Layout for a Preference in a PreferenceActivity. The
Preference is able to place a specific widget for its particular
type in the "widget_frame" layout. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:paddingRight="?android:attr/scrollbarSize"
android:background="?android:attr/selectableItemBackground" >
<ImageView
android:id="@+android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
android:layout_marginBottom="6dip"
android:layout_weight="1">
<TextView android:id="@+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:textAppearance="?android:attr/textAppearanceLarge"
android:ellipsize="marquee"
android:fadingEdge="horizontal" />
<TextView android:id="@+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/title"
android:layout_alignLeft="@android:id/title"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"
android:maxLines="4" />
</RelativeLayout>
<!-- Preference should place its actual preference widget here. -->
<LinearLayout android:id="@+android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical" />
</LinearLayout>
这里我特意把标题的TextView
中的android:singleLine
值从true
改成了false
。这样就可以了。
关于android - 如何处理 Android 首选项中的长文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15853773/
有谁知道如何使 DIV 的行为方式使其始终尝试占用其最大空间(无论内容如何)? 例如,如果我有一个 max-height 的 DIV的 600px和一个 min-height的 200px ,我怎样才
考虑两个表表A和表B 表A |id|driver_id|vehicle_id|is_allowed|license_number|driver_name| 表B |id|driver_id|vehic
对于 ASP.NET 应用程序,自定义脏话删除器/替换器的最佳实践实现方法是什么? 如果这是一个数据表解决方案,是否有免费的资源来获取数据? (类似于找到可以导入到系统中进行拼写检查的公共(publi
有很多 jquery 工具提示插件。 我应该使用哪一个?为什么? 最佳答案 我们使用过qTip在我们的一个项目中,因为它符合我们的所有要求,开发和维护良好,附带优秀的文档和已经很漂亮的模板,并且还为我
我在Internet上四处张望,找不到相关信息。我的程序需要向PowerShell配置文件中编写一些PowerShell代码。如果没有配置文件,我的程序将创建一个。问题是应使用哪种编码来创建Power
在 D、int、uint 中使用 foreach 时,循环索引的首选类型是什么?或者只是通过省略类型自动实现? 最佳答案 一般来说,索引应该是size_t。与长度相同。如果您尝试使用 int 或 ui
这个问题在这里已经有了答案: Repeat each row of data.frame the number of times specified in a column (9 个回答) 2年前关闭
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
我有一个看起来像这样的字符串: "Element 1 | Element 2| Element 3: element 4" 我想对冒号后面的源字符串部分进行子串(到源字符串的末尾),但如果没有冒号,那
我接受任何解释语言 Perl、Python、Bash 等。但我更喜欢 Perl,因为它是我想要学习的。我有一个时间戳列表,例如: 17:31:16 17:31:16 17:31:18 17:31:29
我想在后台运行程序。首选 C#我想把图标放在托盘里。在指定的时间同步文件夹(我知道如何同步文件夹)。如何在后台运行它并开始同步(例如凌晨 2 点)? 最佳答案 您需要考虑使用 windows sche
我有一个 onChange 事件处理程序,它的结构如下: (e) => (value => this.setState(prevState => ({ form: {
我想在windows 7中捕获删除操作。如果用户从计算机上删除了文件,我需要在文件被删除时存储一条记录,以及删除了哪个文件。 一般文件操作,不针对特定文件夹或软件。所以假设用户从 d:\testFol
是否有任何库或开源函数可以近似通过以不规则间隔获取的一些值来描述的线下的面积? 首选 Action Script,但 Java 也可以正常工作。 最佳答案 您可以使用as3mathlib数学图书馆。这
对于我的网络应用程序,我希望提供给用户的图像具有响应性。此外,我还想在图像标签中指定 width 和 height 属性,这样在移动连接速度较慢的情况下,就不会出现浏览器重排。 是否可以通过使用纯 H
在展示公司 Logo 时,我今天看到了一些新东西。 他们在 h1 标签上设置了高度和宽度以及 overflow:hidden 并在 h1 标签内的 a 标签上设置了负边距以防止文本显示。 代码是这样的
我使用 Lucene 库开发了一个索引和搜索应用程序。但是这个库在我的上下文中在自定义排名方面有一些限制,除了它的性能之外,我需要可扩展性和访问各种词频等。是否有任何强大的开源全文库可用? 最佳答案
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 8 年前。 Improve
这是一个关于当我需要在列表中查找对象实例时如何实现 equals 方法的问题,该实例的值是我在其成员中拥有的实例之一。 我有一个实现了 equals 的对象: class User { pri
我是一名优秀的程序员,十分优秀!