Android 自定义首选项布局小部件不可见
编辑: 对于任何遇到这种情况的人,我的方法是: 直接为每个首选项设置布局,如中所示:Android 自定义首选项布局小部件不可见,android,android-layout,android-activity,android-fragments,android-preferences,Android,Android Layout,Android Activity,Android Fragments,Android Preferences,编辑: 对于任何遇到这种情况的人,我的方法是: 直接为每个首选项设置布局,如中所示: <CheckboxPreference android:layout="@layout/checkbox_preference_item"/> 我试图自定义复选框首选项的布局,但复选框本身没有显示。我是根据android代码建模的,不知道哪里出错了。文本视图与布局的其余部分一样工作正常,但复选框未显示。非常感谢您的帮助 相关代码: theme.xml: <style name="Th
<CheckboxPreference
android:layout="@layout/checkbox_preference_item"/>
我试图自定义复选框首选项的布局,但复选框本身没有显示。我是根据android代码建模的,不知道哪里出错了。文本视图与布局的其余部分一样工作正常,但复选框未显示。非常感谢您的帮助
相关代码:
theme.xml:
<style name="Theme.Settings" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">@style/SettingsActionBarStyle</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:preferenceCategoryStyle">@style/PreferenceCategory</item>
<item name="android:preferenceStyle">@style/Preference</item>
<item name="android:checkBoxPreferenceStyle">@style/Checkbox</item>
</style>
@样式/设置事务栏样式
真的
@空的
@风格/偏好类别
@风格/偏好
@样式/复选框
style.xml
<style name="Checkbox">
<item name="android:layout">@layout/checkbox_preference_item</item>
</style>
<style name="Preference.Text">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:fontFamily">sans-serif-light</item>
<item name="android:textSize">@dimen/preferences_item_font</item>
<item name="android:textColor">@color/preference_text</item>
</style>
<style name="Preference.Text.Extra" parent="Preference.Text">
<item name="android:textSize">@dimen/preferences_header_font</item>
</style>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/preferences_item_height"
android:background="@color/white"
android:paddingLeft="@dimen/preferences_item_left">
<LinearLayout android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:gravity="center_vertical">
<TextView android:id="@android:id/title"
style="@style/Preference.Text"/>
<TextView android:id="@android:id/summary"
style="@style/Preference.Text.Extra"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible"
android:id="@android:id/widget_frame"
android:layout_alignParentRight="true"/>
</RelativeLayout>
@布局/复选框\首选项\项目
包装内容
包装内容
无衬线灯
@尺寸/首选项\u项目\u字体
@颜色/首选项\u文本
@尺寸/首选项\u页眉\u字体
复选框\u首选项\u item.xml
<style name="Checkbox">
<item name="android:layout">@layout/checkbox_preference_item</item>
</style>
<style name="Preference.Text">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:fontFamily">sans-serif-light</item>
<item name="android:textSize">@dimen/preferences_item_font</item>
<item name="android:textColor">@color/preference_text</item>
</style>
<style name="Preference.Text.Extra" parent="Preference.Text">
<item name="android:textSize">@dimen/preferences_header_font</item>
</style>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/preferences_item_height"
android:background="@color/white"
android:paddingLeft="@dimen/preferences_item_left">
<LinearLayout android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:gravity="center_vertical">
<TextView android:id="@android:id/title"
style="@style/Preference.Text"/>
<TextView android:id="@android:id/summary"
style="@style/Preference.Text.Extra"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible"
android:id="@android:id/widget_frame"
android:layout_alignParentRight="true"/>
</RelativeLayout>
我在布局xml中没有看到复选框。我错过什么了吗?您需要指定如下内容:
<CheckBox android:id="..." ... />
然后您可能需要指定如下内容
<CheckBoxPreference android:key="..." ... />
在首选项xml文件中。设置应为android:widgetLayout以选中自定义复选框
看到这篇文章可能会对你有更多帮助我的印象是复选框会自动添加到widget_frame linearlayout,仿照此:我实际上并没有试图自定义复选框本身,在这种情况下,仅包含它的容器-请参见-我认为布局高度可能会限制复选框的可见性-奇怪…如果我直接在settings.xml中为首选项设置布局,就像在该链接中一样,它会起作用,但如果我只是尝试为所有首选项设置样式(因此我不必为每个首选项都这样做)它不起作用。谢谢你!