0
我已經擴展了PreferenceCategory類。它的工作原理除了Android屬性「標題」沒有被傳遞並顯示在屏幕上。任何幫助,將不勝感激。這裏是我的代碼:如何擴展PreferenceCategory類
XML \ preferences_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:key="advanced_settings_screen">
<apps.test.CustomPreferenceCategory
android:key="advanced_general_settings_category"
android:title="@string/general_category">
<!-- Other Preferences Here -->
</apps.test.CustomPreferenceCategory>
</PreferenceScreen>
CustomPreferenceCategory.java
public class CustomPreferenceCategory extends PreferenceCategory {
public CustomPreferenceCategory(Context context, AttributeSet attrs) {
super(context, attrs);
Log.v("Constructor 1");
this.setLayoutResource(R.layout.custom_preference_category);
String titleAttribute = _attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "title");
if(titleAttribute.startsWith("@")){
titleAttribute = _context.getString(Integer.parseInt(titleAttribute.replace("@", "")));
}
//What can I do here to populate the custom view with the title? I can't seem to figure this part out.
}
public CustomPreferenceCategory(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
Log.v("Constructor 2");
this.setLayoutResource(R.layout.custom_preference_category);
}
}
佈局\ custom_preference_category.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget_frame"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingTop="25dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold"
android:text="TEST" />
<ImageView
android:id="@+id/category_divider"
android:src="@drawable/preference_divider_normal"
android:layout_height="2dip"
android:layout_width="fill_parent"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp" />
</LinearLayout>
我只想讓「TITLE」屬性通過並顯示在屏幕上。我能夠獲得「標題」attirbute,但現在我似乎無法弄清楚如何將標題設置到自定義視圖中。有人能幫忙嗎?
感謝
大:)我現在有標題。 (我用新的問題和新的代碼更新了問題。)我如何將標題設置到View中?你能幫助我嗎? – 2012-02-17 14:55:35