<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res/com.seedshope.android"
android:title="@string/settings_label"
android:key="parent">
<com.seedshope.android.IconPreferenceScreen
android:title="@string/radio_controls_title"
settings:icon="@drawable/ic_settings_wireless">
<intent
android:action="android.intent.action.MAIN"
android:targetPackage="com.seedshope.android"
android:targetClass="com.seedshope.android.WirelessSettings" />
</com.seedshope.android.IconPreferenceScreen>
</PreferenceScreen>
其中com.seedshope.android.IconPreferenceScreen就是自己定制的风格,其实一个java类,在android系统的路径为com.android.settings.IconPreferenceScreen.也就是packages/apps/Settings/src/com/android/settings/IcomPreferenceScreen.java文件,该文件内容如下:
public class IconPreferenceScreen extends Preference {
private Drawable mIcon;
public IconPreferenceScreen(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public IconPreferenceScreen(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setLayoutResource(R.layout.preference_icon);
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.IconPreferenceScreen, defStyle, 0);
mIcon = a.getDrawable(R.styleable.IconPreferenceScreen_icon);
}
@Override
public void onBindView(View view) {
super.onBindView(view);
ImageView imageView = (ImageView) view.findViewById(R.id.icon);
if (imageView != null && mIcon != null) {
imageView.setImageDrawable(mIcon);
}
}
}
首先继承了Preference,