Custom prefix broken in Honeycomb / ICS

I use the user preference that I use in the title, summary and icon. The prefix is ​​used to select an item (skin, application, etc.), after which it summarizes the current selection. Here preference works correctly (above) and my problem with Honeycomb / ICS:

http://imgur.com/vKPOu

http://imgur.com/EiMBr

Space is done for preference, but even the title / summary is not displayed by default, and the intent to select an item is also not turned off. Here's the location of preferences:

<?xml version="1.0" encoding="UTF-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+android:id/widget_frame" android:layout_width="fill_parent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_vertical" android:paddingRight="?android:attr/scrollbarSize"> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="16dip" android:layout_marginRight="6dip" android:layout_marginTop="6dip" android:layout_marginBottom="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:textAppearance="?android:attr/textAppearanceLarge" android:ellipsize="marquee" android:fadingEdge="horizontal" /> <TextView android:id="@+android:id/summary" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignLeft="@android:id/title" android:textAppearance="?android:attr/textAppearanceSmall" android:maxLines="2" /> </RelativeLayout> <ImageView android:id="@+id/icon" android:layout_width="48dp" android:layout_height="48dp" android:layout_gravity="center" /> </LinearLayout> 

And user preference:

 import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.graphics.drawable.Drawable; import android.preference.Preference; import android.util.AttributeSet; import android.util.Log; import android.view.View; import android.widget.ImageView; public class SelectedAppPreference extends Preference { private Drawable mIcon; public SelectedAppPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final PackageManager pm = context.getPackageManager(); String packageName = context.getSharedPreferences("appPrefs", Context.MODE_PRIVATE).getString("selected_app_package", null); this.setLayoutResource(R.layout.icon_pref); try { this.mIcon = pm.getApplicationIcon(packageName); } catch (NameNotFoundException e) { e.printStackTrace(); } } public SelectedAppPreference(Context context, AttributeSet attrs) { super(context, attrs); final PackageManager pm = context.getPackageManager(); String packageName = context.getSharedPreferences("appPrefs", Context.MODE_PRIVATE).getString("selected_app_package", null); this.setLayoutResource(R.layout.icon_pref); try { this.mIcon = pm.getApplicationIcon(packageName); } catch (NameNotFoundException e) { e.printStackTrace(); } } @Override protected void onBindView(final View view) { super.onBindView(view); final ImageView imageView = (ImageView)view.findViewById(R.id.icon); if ((imageView != null) && (this.mIcon != null)) { imageView.setImageDrawable(this.mIcon); } } public void setIcon(final Drawable icon) { if (((icon == null) && (this.mIcon != null)) || ((icon != null) && (!icon.equals(this.mIcon)))) { this.mIcon = icon; this.notifyChanged(); } } public Drawable getIcon() { return this.mIcon; } } 

Nothing too fascinating about preference. I have the feeling that the problem is in the xml preferences layout, but I'm not sure what exactly is working incorrectly. I can confirm that preference works fine on Android 2.1, 2.2, and 2.3 devices, and I had problems with 3.2 and 4.0. Any suggestions?

+4
source share
2 answers

I had a similar problem with a third-party user preference and fixed it, creating the visibility of the widget frame. This was invisible by default in ICS. Dont "know how it fits your user preferences.

 // This line was in the original code. LinearLayout widgetFrameView = ((LinearLayout) mView .findViewById(android.R.id.widget_frame)); ... // This line fixed the visibility issue widgetFrameView.setVisibility(View.VISIBLE); 

It was also necessary to rebuild the view to fit the rest of the ICS controls.

+6
source

The exclusive preference of the third party that I corrected is taken from this site

https://github.com/attenzione/android-ColorPickerPreference/tree/master/src/net/margaritov/preference/colorpicker

My code (in ColorPickerPreference.setPreviewColor ()) looks like

 widgetFrameView.setVisibility(View.VISIBLE); final boolean preApi14 = android.os.Build.VERSION.SDK_INT < 14; final int rightPaddingDip = preApi14 ? 8 : 5; widgetFrameView.setPadding( widgetFrameView.getPaddingLeft(), widgetFrameView.getPaddingTop(), (int)(mDensity * rightPaddingDip), widgetFrameView.getPaddingBottom() ); 

Where

 float mDensity = getContext().getResources().getDisplayMetrics().density; 

This is with minSdkVersion = 8 and without targetSdkVersion. If you set targetSdkVersion to 14 or more, you may need to change β€œ5” to something else until the user preference item on the right is correctly aligned with the standard ones (for example, check boxes).

+2
source

Source: https://habr.com/ru/post/1389706/


All Articles