【发布时间】:2013-07-20 15:01:29
【问题描述】:
问题:
当 Preference 项列在设置菜单中时,如何更改用于 android:title 属性的文本大小?
详情:
我的应用程序中的设置屏幕在 Nexus 7 (Jelly Bean) 平板电脑上看起来不错,但在摩托罗拉 Defy (Gingerbread) 手机上几乎无法使用。我正在使用 Android 开发指南中详述的标准 PreferenceActivity 方法。
我已经在网上搜索了几天,但没有找到让事情看起来有所不同的解决方案。
在 Android-Gingerbread 手机上;
1) <EditTextPreference android:title .../> 文字太大,不能自动换行。
2) 每个首选项旁边的标准“向下箭头”图标看起来很奇怪且未对齐。 (misaligned icon image)
3) 主题是 Holo,但由于某种原因,最后一个首选项下方的一大块空白区域是难看的浅灰色。
我已经尝试定义 style.xml 资源并将 style="@style/StyleName" 放入 preferences.xml 以更改 android:textSize 属性,但它没有做任何事情。
以下是我的偏好屏幕的 XML:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/SettingsMenu" >
<PreferenceCategory
android:key="pref_key_mixProportions"
android:title="@string/pref_title_mixProportions"
style="@style/SettingsMenu"
>
<EditTextPreference
android:key="pref_key_binderPortion"
android:title="@string/pref_title_binderPortion"
android:dialogTitle="Binder Portion"
android:inputType="numberDecimal"
android:maxLines="2"
android:scrollHorizontally="false"
android:defaultValue="1"
android:persistent="true" />
<EditTextPreference
android:key="pref_key_premixPortion"
android:title="@string/pref_title_premixPortion"
android:dialogTitle="Premix Portion"
android:inputType="numberDecimal"
android:layout_width="wrap_content"
android:maxLines="2"
android:scrollHorizontally="false"
android:defaultValue="5"
android:persistent="true"/>
</PreferenceCategory>
<PreferenceCategory
android:key="pref_key_binderProperties"
android:title="@string/pref_title_binderProperties">
<EditTextPreference
android:key="pref_key_binderDensity"
android:title="@string/pref_title_binderDensity"
android:dialogTitle="Density of Binder powder (kg/m^3)"
android:inputType="numberDecimal"
android:defaultValue="2850"
android:persistent="true"
android:summary="@string/pref_summary_binderDensity"/>
<EditTextPreference
android:key="pref_key_binderBagWeight"
android:title="@string/pref_title_binderBagWeight"
android:dialogTitle="Weight of Binder per bag (kg)"
android:inputType="numberDecimal"
android:defaultValue="20"
android:persistent="true" />
</PreferenceCategory>
<PreferenceCategory
android:key="pref_key_premixProperties"
android:title="@string/pref_title_premixProperties">
<EditTextPreference
android:key="pref_key_premixDensity"
android:title="@string/pref_title_premixDensity"
android:dialogTitle="Density of Sand and Aggregate Mix (kg/m^3)"
android:inputType="numberDecimal"
android:defaultValue="1850"
android:persistent="true"
android:summary="@string/pref_summary_premixDensity"/>
</PreferenceCategory>
</PreferenceScreen>
我的 styles.xml 包含:
<style name="SettingsMenu">
<item name="android:textSize">15sp</item>
</style>
但是无论我为大小指定什么值,文本看起来都是一样的。
我看到有些人建议使用<PreferenceScreen android:layout=".... />,但我没有找到关于如何完成的明确解释。
谁能帮忙?
【问题讨论】:
-
使用图片链接编辑您的帖子,然后将其内联或仅在此处发布网址。如果您需要先上传到某个地方,请上传到 imgur
-
“主题是 Holo dark” -- Android 2.3 上没有
Theme.Holo或Theme.Holo.Dark。 -
尝试使用 ActionBarSherlock。这模仿了较新 Android 版本的样式。
-
如果您想在所有平台上复制 Holo 风格,HoloEverywhere 就是您想要的。
-
我已将图片上传到 imgur 并编辑了帖子。
标签: android xml preferencescreen