1

我在我的程序中使用了扩展的 listView。

这是主布局的代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
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=".MainActivity" >

<ExpandableListView
    android:id="@+id/listView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    android:choiceMode="singleChoice">
</ExpandableListView>

这是组详细信息的代码:

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_marginLeft="8dp"
android:drawableRight="@drawable/ic_launcher"
android:gravity="left"
android:paddingLeft="32dp"
android:paddingTop="8dp"
android:text="@string/Text"
android:textAlignment="textEnd"
android:textSize="14sp"
android:textStyle="bold" />

这是儿童的代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="40dp"
android:clickable="true"
android:orientation="vertical"
android:paddingLeft="40dp"
tools:context=".MainActivity" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/ic_launcher"
    android:drawablePadding="5dp"
    android:gravity="center_vertical"
    android:text="@string/hello_world"
    android:textSize="14sp"
    android:textStyle="bold" >
</TextView>

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="@android:color/black" />

 </LinearLayout>

下面是 onCreate 方法的代码:

 protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
createData();
ExpandableListView listView = (ExpandableListView) findViewById(R.id.listView);
MyExpandableListAdapter adapter = new MyExpandableListAdapter(this,
    groups);
listView.setAdapter(adapter);
listView.setBackgroundDrawable(getResources().getDrawable(R.drawable.red_button));
}

如您所见,我曾经为 listView 设置背景。

listView.setBackgroundDrawable(getResources().getDrawable(R.drawable.red_button));

我想接触孩子并为他们设置背景。谁能帮我做到这一点?

4

0 回答 0