我从PreferenceCategory
扩展,因此我可以将其文本颜色更改为红色(请参见屏幕截图)。但事实证明,最后的Preference字段不再显示,它在底部被切断。我用红色表示应该显示偏好。
正如您在我的实现中所看到的,我没有覆盖任何其他内容:
public class PreferenceCategoryDangerZone extends PreferenceCategory {
public PreferenceCategoryDangerZone(Context context) {
super(context);
}
public PreferenceCategoryDangerZone(Context context, AttributeSet attrs) {
super(context, attrs);
}
public PreferenceCategoryDangerZone(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
// Tried both with and without this constructor, but same result
@TargetApi(21)
public PreferenceCategoryDangerZone(Context context, AttributeSet attrs,
int defStyle, int defStyleRes) {
super(context, attrs, defStyle, defStyleRes);
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
TextView titleView = (TextView) view.findViewById(android.R.id.title);
titleView.setTextColor(getContext().getResources().getColor(R.color.red));
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
...
<com.mohoff.leapp.ui.components.settings.PreferenceCategoryDangerZone
android:title="@string/setting_cat_danger_zone_title"
android:key="@string/setting_cat_danger_zone">
<Preference android:title="@string/setting_delete_timeslots_title"
android:key="@string/setting_delete_timeslots"/>
<Preference android:title="@string/setting_delete_zones_title"
android:key="@string/setting_delete_zones"/>
<Preference android:title="@string/setting_clean_map_title"
android:summary="@string/setting_clean_map_summary"
android:key="@string/setting_clean_map"/>
</com.mohoff.leapp.ui.components.settings.PreferenceCategoryDangerZone>
</PreferenceScreen>
当我使用默认PreferenceCategory
时,它完美无缺。我尝试在Preference
下面添加PreferenceCategoryDangerZone
。结果,整个类别被正确显示,但新添加的最后一个元素仍然被切断。
关于出了什么问题的任何想法?感谢。