还在为系统黑色的list而烦恼么,不罗嗦 ,先上图
如果只是功能的问题,那么你就要写自己的listview了,黑色的永远不能拿出去丢人,不过这个也挺丢人的,哈哈,各位,不要嘲笑我这个小菜鸟啊
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#E0E0E0"
>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:orientation="vertical"
android:background="@drawable/group_bg"
>
<ImageView
android:id="@+id/UserImage"
android:layout_width="80dp"
android:layout_height="80dp"
/>
<TextView
android:id="@+id/UserName"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_toRightOf="@+id/UserImage"
android:gravity="center"
/>
</RelativeLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:orientation="vertical"
>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="300dp"
android:orientation="vertical"
android:background="#FCFCFC"
android:paddingLeft="20dp"
android:paddingRight="20dp"
>
<ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:listSelector="@drawable/grouplist_item_bg"
android:drawSelectorOnTop="true"
android:cacheColorHint="#00000000"
android:divider="@drawable/group_divider"
android:dividerHeight="2.0px"
android:layout_weight="0.0"
>
</ListView>
</LinearLayout>
</LinearLayout>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="40dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:gravity="center"
android:id="@+id/groupItem"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="18.0sp"
android:textColor="#9D9D9D"
/>
</LinearLayout>
package com.information;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class TestInformationListViewActivity extends Activity {
/** Called when the activity is first created. */
private TextView userName;
private ImageView userImage;
private ListView listView;
List<HashMap<String,String>> list;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
userName = (TextView)findViewById(R.id.UserName);
userImage = (ImageView)findViewById(R.id.UserImage);
userName.setText("hello...");
//改变用户的头像
Drawable drawable = getResources().getDrawable(R.drawable.ic_launcher);
userImage.setBackgroundDrawable(drawable);
listView = (ListView)findViewById(R.id.listview);
list = new ArrayList<HashMap<String,String>>();
for(int i=0 ;i<5;i++){
if(i==0){
HashMap<String,String> map = new HashMap<String,String>();
map.put("first", "设置");
list.add(map);
}
else if(i==1){
HashMap<String,String> map = new HashMap<String,String>();
map.put("first", "账号管理");
list.add(map);
}
else if(i==2){
HashMap<String,String> map = new HashMap<String,String>();
map.put("first", "意见反馈");
list.add(map);
}
else if(i==3){
HashMap<String,String> map = new HashMap<String,String>();
map.put("first", "浏览模式");
list.add(map);
}
else {
HashMap<String,String> map = new HashMap<String,String>();
map.put("first", "关于");
list.add(map);
}
}
SimpleAdapter simpleAdapter = new SimpleAdapter(this, list, R.layout.list_item, new String[]{"first"}, new int[]{R.id.groupItem});
listView.setAdapter(simpleAdapter);
listView.setOnItemClickListener(new ButtonListClickListener());
}
class ButtonListClickListener implements OnItemClickListener{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
Toast.makeText(TestInformationListViewActivity.this, (CharSequence) list.get(position).get("first"), 0).show();
}
}
}