4

제목, 요약 및 아이콘을 사용하는 사용자 정의 환경 설정을 사용하고 있습니다. 기본 설정은 항목 (스킨, 응용 프로그램 등)을 선택한 다음 그 항목을 선택하는 데 사용됩니다. 현재의 선택을 요약 할 것이다. 여기에 제대로 (위) 작업 환경 및 허니컴/ICS에 내 문제는 다음과 같습니다Honeycomb/ICS에서 사용자 정의 기본 설정이 깨졌습니다.

http://imgur.com/vKPOu

http://imgur.com/EiMBr

공간은 기본 설정에 대해 이루어지고 있지만, 심지어 기본 제목/요약 게재되지 않습니다 , 항목 선택의 의도도 발화되지 않습니다.

<?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> 

그리고 사용자 환경 자체 : 기본 설정 자체가 너무 흥미로운

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; 
    } 
} 

아무것도 여기에 기본 레이아웃입니다. 문제가 기본 레이아웃 xml에 있다는 느낌이 들지만 정확하게 작동하지 않는 것은 무엇인지 확실하지 않습니다. Android 2.1, 2.2 및 2.3 장치에서 기본 설정이 제대로 작동하는지 확인할 수 있으며 3.2 및 4.0에 대한 문제가 있습니다. 어떤 제안?

+0

링크가 죽었습니다 .. – marcinj

답변

6

제 3 자의 사용자 지정 환경 설정과 비슷한 문제가있어서 위젯 프레임이 보이도록 수정했습니다. 그것은 ICS에서 기본적으로 보이지 않습니다. '사용자 정의 기본 설정에 어떻게 매핑되는지 알지 못합니다.

// 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); 

또한 ICS 컨트롤의 나머지 부분과 일관되게보기를 재정렬해야했습니다.

+0

아름다운, 그게 문제였습니다. 보기를 재편성하기 위해 변경 한 것을 기억하십니까? – nsiderTalon

+1

Google, 이렇게 급한 변화를하는 이유는 무엇입니까? – Nappy

2

내가 고정 타사 사용자 환경이 사이트

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

내 코드에서 가져옵니다 (ColorPickerPreference.setPreviewColor에())

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() 
       ); 

float mDensity = getContext().getResources().getDisplayMetrics().density; 
처럼 보인다

이것은 minSdkVersion = 8이고 targ가 없습니다 etSdkVersion. targetSdkVersion을 14 이상으로 설정하면 오른쪽의 맞춤 환경 설정 요소가 표준 확인란과 같이 잘 정렬 될 때까지 '5'를 다른 것으로 변경해야 할 수 있습니다.