The problem with the decision made is that it still leaves a gap between the blank icon and the rest of the preference.
The correct solution is to never call setIcon (int); only call setIcon (Drawable).
Thus, a small change in your code will work:
Preference myPreference; ... Drawable originalIcon = myPreference.getIcon(); myPreference.setIcon(mPreference.getContext().getResources().getDrawable( android.R.drawable.btn_star)); ... myPreference.setIcon(originalIcon);
This is due to some unsuccessful code in Preference.onBindView (), which returns to the previously set resource identifier if empty output is passed.
source share