Android 是否可以自定义简单列表项目2?

Android 是否可以自定义简单列表项目2?,android,android-layout,android-listview,customization,Android,Android Layout,Android Listview,Customization,我在代码中使用了simple_list_item_2来创建listview。一切正常,但我想更改布局的背景色。可能吗?这个布局也可以像用户定义的XML一样进行自定义吗?只需像这样创建自己的简单列表\u项\u 2,然后使用它即可 <TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android" <!-- This is your background color--> android

我在代码中使用了simple_list_item_2来创建listview。一切正常,但我想更改布局的背景色。可能吗?这个布局也可以像用户定义的XML一样进行自定义吗?

只需像这样创建自己的
简单列表\u项\u 2
,然后使用它即可

<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
   <!-- This is your background color-->
   android:background="#DC143C"

   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:minHeight="?android:attr/listPreferredItemHeight"
   android:mode="twoLine"
   android:paddingStart="?android:attr/listPreferredItemPaddingStart"
   android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
      <TextView android:id="@android:id/text1"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginTop="8dip"
             android:textAppearance="?android:attr/textAppearanceListItem" />
      <TextView android:id="@android:id/text2"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_below="@android:id/text1"
             android:layout_alignStart="@android:id/text1"
             android:textAppearance="?android:attr/textAppearanceListItemSecondary" />
 </TwoLineListItem>

在我看来你不能,但是你可以用相同的代码创建另一个布局,然后替换
简单列表项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目项目

编辑*

按照@JonasCz的答案,您可以编辑它,替换它的示例代码如下:

ListView l = (ListView) findViewById(R.id.listview);
String[] values = new String[] { "Ubuntu", "Android", "iPhone",
    "Windows", "Ubuntu", "Android", "iPhone", "Windows" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
    R.layout.your_custom_simple_list_item_2, values); //removed the android. 
viewContainer = findViewById(R.id.undobar);
l.setAdapter(adapter);
ListView l=(ListView)findViewById(R.id.ListView);
字符串[]值=新字符串[]{“Ubuntu”、“Android”、“iPhone”,
“Windows”、“Ubuntu”、“Android”、“iPhone”、“Windows”};
ArrayAdapter=新的ArrayAdapter(此,
R.layout.your_自定义_简单_列表_项目_2,值)//删除了android。
viewContainer=findViewById(R.id.undobar);
l、 设置适配器(适配器);

代码来自

IMO您不能,但您可以使用相同的代码创建另一个布局,然后替换简单列表项目项目项目项目2的背景,然后将其更改为您想要的颜色,然后调用您的新布局,而不是调用简单列表项目项目项目项目项目项目2。只需提供您的自定义行布局即可。感谢您的回复。我正在创造另一个layout@user232803请看我的编辑:P这可能会有帮助,谢谢!我正在根据你的回答创建新的布局我在这行中遇到了错误,因为我当前的最小值是11。还有什么可以替代这个吗?android:textAppearance=“?android:attr/textAppearanceListItem”