如何在列表首选项中的每个项目旁边添加图标在Android中以及所选指标

问题描述 投票:1回答:1

我正在使用Xposed模块,我需要在列表首选项中的每个项目旁边有一个图标。我能够做到这一点:

http://s20.postimg.org/gjveleu5p/Screenshot_2014_01_18_16_47_38.png

但我想要完全像这一个:

http://s20.postimg.org/ee13qwqp9/Screenshot_2014_01_29_12_32_38.png

我的Java类文件:

package ic.lunar.xposed.exthemer.list.preferences;

import ic.lunar.xposed.exthemer.R;
import android.content.Context;
import android.preference.ListPreference;
import android.util.AttributeSet;

public class Sim_Icon_List_Preference extends ListPreference {

Context context;

public Sim_Icon_List_Preference(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;
    setDialogLayoutResource(R.layout.activity_my_list_preference); //inherited from DialogPreference
}
}

我的布局Xml文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".MyListPreference" >
<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:src="@drawable/tw_sim_icon_home" />
<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/imageView1"
    android:layout_toRightOf="@+id/imageView1"
    android:src="@drawable/tw_sim_icon_heart" />
</RelativeLayout>
android listview android-preferences preferenceactivity listpreference
1个回答
0
投票

当您需要带有(每行)文本和图标的ListPreference时,您可以通过此description找到解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.