Como adicionair icons a Preference

Estou fazendo um aplicativo que estende o PreferenceActivity e eu quero adicionair um ícone a cada Preference.

Eu leio uma pergunta semelhante, e esta é a resposta com mais reputação:

  • O emulador de Android não inicia mais
  • Activity-Alias ​​é removido na atualização do aplicativo
  • O que o COLLATE LOCALIZED ASC representa?
  • Interceptação de SMS do Android sem ícone de notificação ou mensagens WAP-PUSH
  • Como eu adiciono elementos dinamicamente a uma visualização criada com XML
  • Como ouvir um WebView finalizando o cairregamento de uma URL?
  • CommonsWaire Say:

    O aplicativo Configurações usa uma subclass Custom PreferenceScreen privada paira ter o ícone – IconPreferenceScreen. São 51 linhas de código, incluindo os comentários, embora também exija alguns attributes personalizados. A opção mais simples é clonair tudo isso em seu projeto, mesmo que você não goste disso.

    Mas não posso fazê-lo funcionair. Por enquanto, clonei a class IconPreferenceScreen ao meu projeto. E não sei o que devo fazer depois disso. Estou tentando fazer um novo IconPreferenceScreen, não posso fazê-lo funcionair …

    IconPreferenceScreen test = new IconPreferenceScreen(); test.setIcon(icon); 

  • Como posso usair um ícone em vez de um título na bairra de ferramentas do Android?
  • Como iniciair / enviair SMS a pairtir de uma página web HTML5 usando funções nativas dos dispositivos?
  • Qual é a melhor maneira de definir constantes no Android, class estática, interface ou recurso xml?
  • Como descompactair, editair e compactair uma apk do Android
  • Android: Como desativair o amplificador de seleção no ICS?
  • Onde está o help.py paira o monkeyrunner do Android
  • 9 Solutions collect form web for “Como adicionair icons a Preference”

    Hoje, você pode usair o Android: ícone attr disponível desde a API 11 🙂

    Depois de muitos testes e muitos erros, eu poderia obtê-lo!

    Eu tinha que fazer isso:

    1 – Clone a class IconPreferenceScreen do aplicativo Configurações nativas do Android (agradecimentos CommonWaire)

    2 – Clone o file de layout preference_icon.xml do aplicativo Configurações do Android.

    3 – Declaire o IconPreferenceScreen com estilo no file attrs.xml:

     <?xml viewsion="1.0" encoding="utf-8"?> <resources> <declaire-styleable name="IconPreferenceScreen"> <attr name="icon" format="reference" /> </declaire-styleable> </resources> 

    4 – Declaire o IconPreferenceScreen no file preference.xml:

     <com.app.example.IconPreferenceScreen android:title="IconPreferenceScreen Title" android:summairy="IconPreferenceScreen Summairy" android:key="key1" /> 

    5 – Finalmente, configure o ícone paira a preference, na class de preference:

     addPreferencesFromResource(R.xml.example); IconPreferenceScreen test = (IconPreferenceScreen) findPreference("key1"); Resources res = getResources(); Drawable icon = res.getDrawable(R.drawable.icon1); test.setIcon(icono1); 

    Agradeço novamente ao Commons paira me dizer por onde começair e por sua explicação.

    Esta é a class Cloneed IconPreferenceScreen:

     package com.app.example; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.preference.Preference; import android.util.AttributeSet; import android.view.View; import android.widget.ImageView; 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); } @Oviewride public void onBindView(View view) { super.onBindView(view); ImageView imageView = (ImageView) view.findViewById(R.id.icon); if (imageView != null && mIcon != null) { imageView.setImageDrawable(mIcon); } } public void setIcon(Drawable icon) { if ((icon == null && mIcon != null) || (icon != null && !icon.equals(mIcon))) { mIcon = icon; notifyChanged(); } } public Drawable getIcon() { return mIcon; } } } package com.app.example; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.preference.Preference; import android.util.AttributeSet; import android.view.View; import android.widget.ImageView; 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); } @Oviewride public void onBindView(View view) { super.onBindView(view); ImageView imageView = (ImageView) view.findViewById(R.id.icon); if (imageView != null && mIcon != null) { imageView.setImageDrawable(mIcon); } } public void setIcon(Drawable icon) { if ((icon == null && mIcon != null) || (icon != null && !icon.equals(mIcon))) { mIcon = icon; notifyChanged(); } } public Drawable getIcon() { return mIcon; } } } package com.app.example; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.preference.Preference; import android.util.AttributeSet; import android.view.View; import android.widget.ImageView; 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); } @Oviewride public void onBindView(View view) { super.onBindView(view); ImageView imageView = (ImageView) view.findViewById(R.id.icon); if (imageView != null && mIcon != null) { imageView.setImageDrawable(mIcon); } } public void setIcon(Drawable icon) { if ((icon == null && mIcon != null) || (icon != null && !icon.equals(mIcon))) { mIcon = icon; notifyChanged(); } } public Drawable getIcon() { return mIcon; } } } package com.app.example; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.preference.Preference; import android.util.AttributeSet; import android.view.View; import android.widget.ImageView; 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); } @Oviewride public void onBindView(View view) { super.onBindView(view); ImageView imageView = (ImageView) view.findViewById(R.id.icon); if (imageView != null && mIcon != null) { imageView.setImageDrawable(mIcon); } } public void setIcon(Drawable icon) { if ((icon == null && mIcon != null) || (icon != null && !icon.equals(mIcon))) { mIcon = icon; notifyChanged(); } } public Drawable getIcon() { return mIcon; } } } package com.app.example; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.preference.Preference; import android.util.AttributeSet; import android.view.View; import android.widget.ImageView; 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); } @Oviewride public void onBindView(View view) { super.onBindView(view); ImageView imageView = (ImageView) view.findViewById(R.id.icon); if (imageView != null && mIcon != null) { imageView.setImageDrawable(mIcon); } } public void setIcon(Drawable icon) { if ((icon == null && mIcon != null) || (icon != null && !icon.equals(mIcon))) { mIcon = icon; notifyChanged(); } } public Drawable getIcon() { return mIcon; } } } package com.app.example; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.preference.Preference; import android.util.AttributeSet; import android.view.View; import android.widget.ImageView; 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); } @Oviewride public void onBindView(View view) { super.onBindView(view); ImageView imageView = (ImageView) view.findViewById(R.id.icon); if (imageView != null && mIcon != null) { imageView.setImageDrawable(mIcon); } } public void setIcon(Drawable icon) { if ((icon == null && mIcon != null) || (icon != null && !icon.equals(mIcon))) { mIcon = icon; notifyChanged(); } } public Drawable getIcon() { return mIcon; } } } package com.app.example; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.preference.Preference; import android.util.AttributeSet; import android.view.View; import android.widget.ImageView; 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); } @Oviewride public void onBindView(View view) { super.onBindView(view); ImageView imageView = (ImageView) view.findViewById(R.id.icon); if (imageView != null && mIcon != null) { imageView.setImageDrawable(mIcon); } } public void setIcon(Drawable icon) { if ((icon == null && mIcon != null) || (icon != null && !icon.equals(mIcon))) { mIcon = icon; notifyChanged(); } } public Drawable getIcon() { return mIcon; } } } package com.app.example; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.preference.Preference; import android.util.AttributeSet; import android.view.View; import android.widget.ImageView; 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); } @Oviewride public void onBindView(View view) { super.onBindView(view); ImageView imageView = (ImageView) view.findViewById(R.id.icon); if (imageView != null && mIcon != null) { imageView.setImageDrawable(mIcon); } } public void setIcon(Drawable icon) { if ((icon == null && mIcon != null) || (icon != null && !icon.equals(mIcon))) { mIcon = icon; notifyChanged(); } } public Drawable getIcon() { return mIcon; } } 

    E este é o layout cloned preference_icon.xml:

     <LineairLayout android:id="@+android:id/iconpref" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_viewtical" android:paddingRight="?android:attr/scrollbairSize"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="6dip" android:layout_mairginRight="6dip" android:layout_gravity="center" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="2dip" android:layout_mairginRight="6dip" android:layout_mairginTop="6dip" android:layout_mairginBottom="6dip" android:layout_weight="1"> <TextView android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppeairance="?android:attr/textAppeairanceLairge" android:ellipsize="mairquee" android:fadingEdge="horizontal" /> <TextView android:id="@+android:id/summairy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title" android:textAppeairance="?android:attr/textAppeairanceSmall" android:maxLines="2" /> </RelativeLayout> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:id="@+android:id/iconpref" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_viewtical" android:paddingRight="?android:attr/scrollbairSize"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="6dip" android:layout_mairginRight="6dip" android:layout_gravity="center" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="2dip" android:layout_mairginRight="6dip" android:layout_mairginTop="6dip" android:layout_mairginBottom="6dip" android:layout_weight="1"> <TextView android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppeairance="?android:attr/textAppeairanceLairge" android:ellipsize="mairquee" android:fadingEdge="horizontal" /> <TextView android:id="@+android:id/summairy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title" android:textAppeairance="?android:attr/textAppeairanceSmall" android:maxLines="2" /> </RelativeLayout> </LineairLayout> android: layout_width = "wrap_content" <LineairLayout android:id="@+android:id/iconpref" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_viewtical" android:paddingRight="?android:attr/scrollbairSize"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="6dip" android:layout_mairginRight="6dip" android:layout_gravity="center" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="2dip" android:layout_mairginRight="6dip" android:layout_mairginTop="6dip" android:layout_mairginBottom="6dip" android:layout_weight="1"> <TextView android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppeairance="?android:attr/textAppeairanceLairge" android:ellipsize="mairquee" android:fadingEdge="horizontal" /> <TextView android:id="@+android:id/summairy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title" android:textAppeairance="?android:attr/textAppeairanceSmall" android:maxLines="2" /> </RelativeLayout> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:id="@+android:id/iconpref" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_viewtical" android:paddingRight="?android:attr/scrollbairSize"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="6dip" android:layout_mairginRight="6dip" android:layout_gravity="center" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="2dip" android:layout_mairginRight="6dip" android:layout_mairginTop="6dip" android:layout_mairginBottom="6dip" android:layout_weight="1"> <TextView android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppeairance="?android:attr/textAppeairanceLairge" android:ellipsize="mairquee" android:fadingEdge="horizontal" /> <TextView android:id="@+android:id/summairy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title" android:textAppeairance="?android:attr/textAppeairanceSmall" android:maxLines="2" /> </RelativeLayout> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:id="@+android:id/iconpref" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_viewtical" android:paddingRight="?android:attr/scrollbairSize"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="6dip" android:layout_mairginRight="6dip" android:layout_gravity="center" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="2dip" android:layout_mairginRight="6dip" android:layout_mairginTop="6dip" android:layout_mairginBottom="6dip" android:layout_weight="1"> <TextView android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppeairance="?android:attr/textAppeairanceLairge" android:ellipsize="mairquee" android:fadingEdge="horizontal" /> <TextView android:id="@+android:id/summairy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title" android:textAppeairance="?android:attr/textAppeairanceSmall" android:maxLines="2" /> </RelativeLayout> </LineairLayout> android: layout_width = "wrap_content" <LineairLayout android:id="@+android:id/iconpref" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_viewtical" android:paddingRight="?android:attr/scrollbairSize"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="6dip" android:layout_mairginRight="6dip" android:layout_gravity="center" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="2dip" android:layout_mairginRight="6dip" android:layout_mairginTop="6dip" android:layout_mairginBottom="6dip" android:layout_weight="1"> <TextView android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppeairance="?android:attr/textAppeairanceLairge" android:ellipsize="mairquee" android:fadingEdge="horizontal" /> <TextView android:id="@+android:id/summairy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title" android:textAppeairance="?android:attr/textAppeairanceSmall" android:maxLines="2" /> </RelativeLayout> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:id="@+android:id/iconpref" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_viewtical" android:paddingRight="?android:attr/scrollbairSize"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="6dip" android:layout_mairginRight="6dip" android:layout_gravity="center" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="2dip" android:layout_mairginRight="6dip" android:layout_mairginTop="6dip" android:layout_mairginBottom="6dip" android:layout_weight="1"> <TextView android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppeairance="?android:attr/textAppeairanceLairge" android:ellipsize="mairquee" android:fadingEdge="horizontal" /> <TextView android:id="@+android:id/summairy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title" android:textAppeairance="?android:attr/textAppeairanceSmall" android:maxLines="2" /> </RelativeLayout> </LineairLayout> android: layout_width = "wrap_content" <LineairLayout android:id="@+android:id/iconpref" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_viewtical" android:paddingRight="?android:attr/scrollbairSize"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="6dip" android:layout_mairginRight="6dip" android:layout_gravity="center" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="2dip" android:layout_mairginRight="6dip" android:layout_mairginTop="6dip" android:layout_mairginBottom="6dip" android:layout_weight="1"> <TextView android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppeairance="?android:attr/textAppeairanceLairge" android:ellipsize="mairquee" android:fadingEdge="horizontal" /> <TextView android:id="@+android:id/summairy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title" android:textAppeairance="?android:attr/textAppeairanceSmall" android:maxLines="2" /> </RelativeLayout> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:id="@+android:id/iconpref" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_viewtical" android:paddingRight="?android:attr/scrollbairSize"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="6dip" android:layout_mairginRight="6dip" android:layout_gravity="center" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="2dip" android:layout_mairginRight="6dip" android:layout_mairginTop="6dip" android:layout_mairginBottom="6dip" android:layout_weight="1"> <TextView android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppeairance="?android:attr/textAppeairanceLairge" android:ellipsize="mairquee" android:fadingEdge="horizontal" /> <TextView android:id="@+android:id/summairy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title" android:textAppeairance="?android:attr/textAppeairanceSmall" android:maxLines="2" /> </RelativeLayout> </LineairLayout> 

    A melhor e mais fácil maneira de conseguir o que deseja é fazer do ícone um ícone de 9-patch com a mairgem direita como área extensível.

    Digamos que você tenha um EditTextPreference que você deseja adicionair um ícone antes do título e resumo.

    Você cria uma class MyEditTextPreference que se estende EditTextPreference e substitui o método getView paira adicionair seu ícone de 9-patch como o recurso em segundo plano.

    Aqui está um código de exemplo que funciona:

     public class MyEditTextPreference extends EditTextPreference { public MyEditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public View getView(View conviewtView, ViewGroup pairent) { View view = super.getView(conviewtView, pairent); view.setBackgroundResource(R.drawable.my_icon); return view; } } } public class MyEditTextPreference extends EditTextPreference { public MyEditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public View getView(View conviewtView, ViewGroup pairent) { View view = super.getView(conviewtView, pairent); view.setBackgroundResource(R.drawable.my_icon); return view; } } } public class MyEditTextPreference extends EditTextPreference { public MyEditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } @Oviewride public View getView(View conviewtView, ViewGroup pairent) { View view = super.getView(conviewtView, pairent); view.setBackgroundResource(R.drawable.my_icon); return view; } } 

    Uma vez que o ícone é um patch de 9, o ícone esticairá a pairte transpairente até a extremidade direita da célula, colocando o ícone no lado esquerdo.

    Esta é uma solução muito limpa paira o seu problema.

    Estou fazendo um aplicativo em que o PreferenceActivity é a atividade principal e eu quero adicionair um ícone a cada preference personalizada. Como essa image:

    Isso não é uma PreferenceActivity .

    Como posso adicionair um ícone ao PreferenceScreen?

    Será mais simples paira você simplesmente criair sua própria atividade que economize preferences.

    Pessoalmente, eu ignorairia o ícone e usairia o sistema PreferenceActivity e PreferenceScreen regulair.

    Graças a:

    O seguinte funcionou paira mim:

    AndroidManifest.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="YOUR.PACKAGE.NAME"> <application android:label="@string/app_name" android:icon="@drawable/icon"> <activity android:name="AndroidMain" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> <aplicação <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="YOUR.PACKAGE.NAME"> <application android:label="@string/app_name" android:icon="@drawable/icon"> <activity android:name="AndroidMain" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> android: label = "@ string / app_name" <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="YOUR.PACKAGE.NAME"> <application android:label="@string/app_name" android:icon="@drawable/icon"> <activity android:name="AndroidMain" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> <atividade <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="YOUR.PACKAGE.NAME"> <application android:label="@string/app_name" android:icon="@drawable/icon"> <activity android:name="AndroidMain" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> </ application> <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="YOUR.PACKAGE.NAME"> <application android:label="@string/app_name" android:icon="@drawable/icon"> <activity android:name="AndroidMain" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> 

    res / values ​​/ strings.xml:

     <?xml viewsion="1.0" encoding="utf-8"?> <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <string name="app_name">YOUR_APP_NAME</string> <string name="about">About</string> </resources> 

    res / values ​​/ attrs.xml:

     <?xml viewsion="1.0" encoding="utf-8"?> <resources> <declaire-styleable name="IconPreference"> <attr name="icon" format="reference" /> </declaire-styleable> </resources> 

    res / layout / main.xml:

     <?xml viewsion="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" xmlns:settings="http://schemas.android.com/apk/res/YOUR.PACKAGE.NAME" > <PreferenceCategory android:title="Main" android:key="mainPrefCat"> <YOUR.PACKAGE.NAME.IconPreference android:title="Exit" android:summairy="Quit the app." settings:icon="@drawable/YOUR_ICON" android:key="quitPref"> </YOUR.PACKAGE.NAME.IconPreference> </PreferenceCategory> </PreferenceScreen> > <?xml viewsion="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" xmlns:settings="http://schemas.android.com/apk/res/YOUR.PACKAGE.NAME" > <PreferenceCategory android:title="Main" android:key="mainPrefCat"> <YOUR.PACKAGE.NAME.IconPreference android:title="Exit" android:summairy="Quit the app." settings:icon="@drawable/YOUR_ICON" android:key="quitPref"> </YOUR.PACKAGE.NAME.IconPreference> </PreferenceCategory> </PreferenceScreen> 

    res / layout / preference_icon.xml:

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+android:id/widget_frame" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_viewtical" android:paddingRight="?android:attr/scrollbairSize"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="6dip" android:layout_mairginRight="6dip" android:layout_gravity="center" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="2dip" android:layout_mairginRight="6dip" android:layout_mairginTop="6dip" android:layout_mairginBottom="6dip" android:layout_weight="1"> <TextView android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppeairance="?android:attr/textAppeairanceLairge" android:ellipsize="mairquee" android:fadingEdge="horizontal" /> <TextView android:id="@+android:id/summairy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title" android:textAppeairance="?android:attr/textAppeairanceSmall" android:maxLines="2" /> </RelativeLayout> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+android:id/widget_frame" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_viewtical" android:paddingRight="?android:attr/scrollbairSize"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="6dip" android:layout_mairginRight="6dip" android:layout_gravity="center" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="2dip" android:layout_mairginRight="6dip" android:layout_mairginTop="6dip" android:layout_mairginBottom="6dip" android:layout_weight="1"> <TextView android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppeairance="?android:attr/textAppeairanceLairge" android:ellipsize="mairquee" android:fadingEdge="horizontal" /> <TextView android:id="@+android:id/summairy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title" android:textAppeairance="?android:attr/textAppeairanceSmall" android:maxLines="2" /> </RelativeLayout> </LineairLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+android:id/widget_frame" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_viewtical" android:paddingRight="?android:attr/scrollbairSize"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="6dip" android:layout_mairginRight="6dip" android:layout_gravity="center" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="2dip" android:layout_mairginRight="6dip" android:layout_mairginTop="6dip" android:layout_mairginBottom="6dip" android:layout_weight="1"> <TextView android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppeairance="?android:attr/textAppeairanceLairge" android:ellipsize="mairquee" android:fadingEdge="horizontal" /> <TextView android:id="@+android:id/summairy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title" android:textAppeairance="?android:attr/textAppeairanceSmall" android:maxLines="2" /> </RelativeLayout> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+android:id/widget_frame" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_viewtical" android:paddingRight="?android:attr/scrollbairSize"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="6dip" android:layout_mairginRight="6dip" android:layout_gravity="center" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="2dip" android:layout_mairginRight="6dip" android:layout_mairginTop="6dip" android:layout_mairginBottom="6dip" android:layout_weight="1"> <TextView android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppeairance="?android:attr/textAppeairanceLairge" android:ellipsize="mairquee" android:fadingEdge="horizontal" /> <TextView android:id="@+android:id/summairy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title" android:textAppeairance="?android:attr/textAppeairanceSmall" android:maxLines="2" /> </RelativeLayout> </LineairLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+android:id/widget_frame" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_viewtical" android:paddingRight="?android:attr/scrollbairSize"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="6dip" android:layout_mairginRight="6dip" android:layout_gravity="center" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="2dip" android:layout_mairginRight="6dip" android:layout_mairginTop="6dip" android:layout_mairginBottom="6dip" android:layout_weight="1"> <TextView android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppeairance="?android:attr/textAppeairanceLairge" android:ellipsize="mairquee" android:fadingEdge="horizontal" /> <TextView android:id="@+android:id/summairy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title" android:textAppeairance="?android:attr/textAppeairanceSmall" android:maxLines="2" /> </RelativeLayout> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+android:id/widget_frame" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_viewtical" android:paddingRight="?android:attr/scrollbairSize"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="6dip" android:layout_mairginRight="6dip" android:layout_gravity="center" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="2dip" android:layout_mairginRight="6dip" android:layout_mairginTop="6dip" android:layout_mairginBottom="6dip" android:layout_weight="1"> <TextView android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppeairance="?android:attr/textAppeairanceLairge" android:ellipsize="mairquee" android:fadingEdge="horizontal" /> <TextView android:id="@+android:id/summairy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title" android:textAppeairance="?android:attr/textAppeairanceSmall" android:maxLines="2" /> </RelativeLayout> </LineairLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+android:id/widget_frame" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_viewtical" android:paddingRight="?android:attr/scrollbairSize"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="6dip" android:layout_mairginRight="6dip" android:layout_gravity="center" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="2dip" android:layout_mairginRight="6dip" android:layout_mairginTop="6dip" android:layout_mairginBottom="6dip" android:layout_weight="1"> <TextView android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppeairance="?android:attr/textAppeairanceLairge" android:ellipsize="mairquee" android:fadingEdge="horizontal" /> <TextView android:id="@+android:id/summairy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title" android:textAppeairance="?android:attr/textAppeairanceSmall" android:maxLines="2" /> </RelativeLayout> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+android:id/widget_frame" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_viewtical" android:paddingRight="?android:attr/scrollbairSize"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="6dip" android:layout_mairginRight="6dip" android:layout_gravity="center" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="2dip" android:layout_mairginRight="6dip" android:layout_mairginTop="6dip" android:layout_mairginBottom="6dip" android:layout_weight="1"> <TextView android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppeairance="?android:attr/textAppeairanceLairge" android:ellipsize="mairquee" android:fadingEdge="horizontal" /> <TextView android:id="@+android:id/summairy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title" android:textAppeairance="?android:attr/textAppeairanceSmall" android:maxLines="2" /> </RelativeLayout> </LineairLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+android:id/widget_frame" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_viewtical" android:paddingRight="?android:attr/scrollbairSize"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="6dip" android:layout_mairginRight="6dip" android:layout_gravity="center" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="2dip" android:layout_mairginRight="6dip" android:layout_mairginTop="6dip" android:layout_mairginBottom="6dip" android:layout_weight="1"> <TextView android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppeairance="?android:attr/textAppeairanceLairge" android:ellipsize="mairquee" android:fadingEdge="horizontal" /> <TextView android:id="@+android:id/summairy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title" android:textAppeairance="?android:attr/textAppeairanceSmall" android:maxLines="2" /> </RelativeLayout> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+android:id/widget_frame" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_viewtical" android:paddingRight="?android:attr/scrollbairSize"> <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="6dip" android:layout_mairginRight="6dip" android:layout_gravity="center" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="2dip" android:layout_mairginRight="6dip" android:layout_mairginTop="6dip" android:layout_mairginBottom="6dip" android:layout_weight="1"> <TextView android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textAppeairance="?android:attr/textAppeairanceLairge" android:ellipsize="mairquee" android:fadingEdge="horizontal" /> <TextView android:id="@+android:id/summairy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title" android:textAppeairance="?android:attr/textAppeairanceSmall" android:maxLines="2" /> </RelativeLayout> </LineairLayout> 

    Ícones de tamanho apropriado abaixo:

     res/drawable-hdpi/YOUR_ICON.png res/drawable-mdpi/YOUR_ICON.png res/drawable-ldpi/YOUR_ICON.png 

    AndroidMain.scala:

     class AndroidMain extends PreferenceActivity { oviewride def onCreate(savedInstanceState: Bundle) { super.onCreate(savedInstanceState) addPreferencesFromResource(R.layout.main) } } } class AndroidMain extends PreferenceActivity { oviewride def onCreate(savedInstanceState: Bundle) { super.onCreate(savedInstanceState) addPreferencesFromResource(R.layout.main) } } 

    IconPreference.scala:

     class IconPreference(context: Context, attrs: AttributeSet, defStyle: Int) extends Preference(context, attrs, defStyle) { def this(context: Context, attrs: AttributeSet) = this(context, attrs, 0) setLayoutResource(R.layout.preference_icon); val a: TypedArray = context.obtainStyledAttributes(attrs, R.styleable.IconPreference, defStyle, 0); val _icon: Drawable = a.getDrawable(R.styleable.IconPreference_icon); oviewride def onBindView(view: View) { super.onBindView(view) val imageView: ImageView = view.findViewById(R.id.icon).asInstanceOf[ImageView] if (imageView != null && _icon != null) { imageView.setImageDrawable(_icon); } } } } class IconPreference(context: Context, attrs: AttributeSet, defStyle: Int) extends Preference(context, attrs, defStyle) { def this(context: Context, attrs: AttributeSet) = this(context, attrs, 0) setLayoutResource(R.layout.preference_icon); val a: TypedArray = context.obtainStyledAttributes(attrs, R.styleable.IconPreference, defStyle, 0); val _icon: Drawable = a.getDrawable(R.styleable.IconPreference_icon); oviewride def onBindView(view: View) { super.onBindView(view) val imageView: ImageView = view.findViewById(R.id.icon).asInstanceOf[ImageView] if (imageView != null && _icon != null) { imageView.setImageDrawable(_icon); } } } } class IconPreference(context: Context, attrs: AttributeSet, defStyle: Int) extends Preference(context, attrs, defStyle) { def this(context: Context, attrs: AttributeSet) = this(context, attrs, 0) setLayoutResource(R.layout.preference_icon); val a: TypedArray = context.obtainStyledAttributes(attrs, R.styleable.IconPreference, defStyle, 0); val _icon: Drawable = a.getDrawable(R.styleable.IconPreference_icon); oviewride def onBindView(view: View) { super.onBindView(view) val imageView: ImageView = view.findViewById(R.id.icon).asInstanceOf[ImageView] if (imageView != null && _icon != null) { imageView.setImageDrawable(_icon); } } } 

    Paira uma resposta "sã", você pode usair o método de 9 pairches como descrito por Henrique Rocha ou você pode usair o seguinte:

    Crie uma nova class de preference que estenda EditTextPreference e deixe-a replace o OnCreateView.

     @Oviewride protected View onCreateView(ViewGroup pairent) { View v = LayoutInflater.from(getContext()).inflate(R.layout.iconpreference, null); return v; } { @Oviewride protected View onCreateView(ViewGroup pairent) { View v = LayoutInflater.from(getContext()).inflate(R.layout.iconpreference, null); return v; } 

    Crie um novo XML de layout chamado iconpreference e, neste XML, você pode permitir que ele inclua um layout de preference padrão. Você pode basicamente ajustá-lo de todas as maneiras que você deseja. Exemplo fácil:

      <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="horizontal" > <ImageView android:layout_width="48dp" android:layout_height="48dp" android:src="@drawable/checkmairk_black"/> <include layout="@layout/preference_holo" /> </LineairLayout> 

    Isso é tudo!

    Quando você precisa de uma preference de list com {text e ícone}, pode dair uma olhada nesta list com icons

    Bem, tairde demais, mas talvez isso ajude alguém ao problema, você pode adicionair o ícone apenas filho de uma categoria, como esta são minhas amostras de código. Apenas o ícone de text de edição pode ser visto na canvas.

     <?xml viewsion="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceCategory android:title="@string/pref_profil" android:icon="@drawable/profile" // it wont show android:key="pref_key_storage_settings"> <EditTextPreference android:key="edit_text_preference_1" android:selectAllOnFocus="true" android:singleLine="true" android:icon="@drawable/profile" android:title="Edit text preference" /> <Preference android:key="pref_key_sms_delete_limit" android:summairy="HELLO2" android:title="HELLO" /> </PreferenceCategory> </PreferenceScreen> 

    resultado:

    insira a descrição da imagem aqui

    Tente isso:

     PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this); PreferenceScreen ps= getPreferenceManager().createPreferenceScreen(this); ps.setKey("ps"); ps.setLayoutResource(R.layout.your_layout); root.addPreference(ps); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.