CustomPreferenceCategory无法强制转换为android.preference.GenericInflater $ Parent

时间:2015-11-19 17:52:48

标签: preferenceactivity preference preferencefragment

我做了CustomPreference,它与PreferenceCategory配合得很好,但是CustomPreferenceCategory有一个问题,比如uk.co.bla.bla.customwidget.viewgroup.CustomPreferenceCategory无法强制转换为android.preference.GenericInflater $ Parent

CustomPreferenceCategory.class

public class CustomPreferenceCategory extends PreferenceCategory {
private TextView txt;
public CustomPreferenceCategory(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.setWidgetLayoutResource(R.layout.preference_category_title);
}


@Override
protected void onBindView(View view) {
    super.onBindView(view);
    txt = (TextView) view.findViewById(R.id.text_view_preference_category_title);
}

public void setText(String text, int color) {
    txt.setText(text);
    txt.setTextColor(color);
}
}

preference_category_title

<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/grey_231"
>
<TextView
    android:id="@+id/text_view_preference_category_title"
    android:layout_width="wrap_content"
    android:layout_height="32.5dp"
    android:text="@string/profile_preference"
    android:textSize="14dp"
    android:gravity="center"
    app:layout_marginLeftPercent="3.5%"
    android:textColor="@color/charcoalGrey_30"

    />   
    </android.support.percent.PercentRelativeLayout>

preference.xml

<uk.co.bla.bla.customwidget.viewgroup.CustomPreferenceCategory
    android:name="uk.co.bla.bla.customwidget.viewgroup.CustomPreferenceCategory"
    android:key="@string/profile_preference"
    android:layout="@layout/preference_category_title">

    <uk.co.bla.bla.customwidget.viewgroup.CustomPreferenceButton
        android:name="uk.co.bla.bla.customwidget.viewgroup.CustomPreferenceButton"
        android:layout="@layout/preference_button"
        android:key="@string/edit_profil_button_preference"/>

    <uk.co.bla.bla.customwidget.viewgroup.CustomPreferenceButton
        android:key="@string/change_password_preference"
        android:layout="@layout/preference_button"/>
  </uk.co.bla.bla.customwidget.viewgroup.CustomPreferenceCategory>

1 个答案:

答案 0 :(得分:1)

SOLUTION:使缓存无效/重新启动