所以我为我的偏好活动中的一个偏好构建了一个自定义偏好视图:
<Preference 
      android:key="facebook_sharing"
      android:layout="@layout/fb_pref_item"/>
我希望能够以编程方式编辑该自定义首选项布局中的 ImageView(基于首选项本身的值。
它看起来像这样:
Preference facebookItem = (Preference)findPreference("facebook_sharing");
facebookItem.setOnPreferenceChangeListener(this);
RelativeLayout rl = //get relative layout someway or another...
mFacebookIcon = (ImageView)rl.findViewById(R.id.fb_imgview);
if(!mFacebookConn.isSessionValid())
    mFacebookIcon.setColorFilter(R.color.transparent_black);
我不知道如何取消注释行。我尝试了以下方法:
RelativeLayout rl = (RelativeLayout)facebookItem.getView(null, null); //dont know what the params ought to be...
RelativeLayout rl = (RelativeLayout)findViewById(facebookItem.getLayoutResource());
都不工作。我四处寻找,但似乎找不到任何尝试过这个的人。有任何想法吗?谢谢!
编辑:提供 fb_pref_item:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fb_view"
    android:layout_width="match_parent"
    android:layout_height="68dp" >
    <TextView android:id="@+id/fb_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="2dp"
        android:layout_alignParentTop="true"
        android:text="@string/facebook"
        android:textSize="20sp"
        android:textColor="@color/item_view_text_color" />
    <TextView android:id="@+id/fb_description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="4dp"
        android:layout_marginBottom="8dp"
        android:layout_alignParentBottom="true"
        android:layout_below="@id/fb_title" />
    <ImageView android:id="@+id/fb_imgview"
        android:src="@drawable/facebook64"
        android:layout_width="42dp"
        android:layout_height="42dp"
        android:layout_centerVertical="true"
        android:layout_margin="12dp"  
        android:layout_alignParentRight="true" 
        android:scaleType="centerInside"
        android:contentDescription="@string/cd_icon"/>
</RelativeLayout>