zts4690 2014年01月10日
android app开发 列表背景色
现在列表的背景色是白的。像这样:
activity_txl.xml的代码如下:

<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="match_parent"
android:orientation="vertical" >

<LinearLayout android:id="@+id/ads" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content">
<FrameLayout android:gravity="center_vertical" android:orientation="horizontal" android:background="@drawable/lt_app_page_titlebar" android:layout_width="fill_parent" android:layout_height="40.0dip">
<LinearLayout android:gravity="center" android:focusable="true" android:clickable="true" android:layout_width="32.0dip" android:layout_height="40.0dip">
<ImageView android:gravity="center" android:background="@drawable/lt_btn_app_man_back_normal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="onBackButtonClick" />
</LinearLayout>
<TextView android:textSize="22.0dip" android:textColor="@android:color/white" android:gravity="center_horizontal" android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/title_activity_txl" />
</FrameLayout>
</LinearLayout>

<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
/>

<LinearLayout
android:id="@+id/list_no_result"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/msg_no_result" />
</LinearLayout>

<LinearLayout
android:id="@+id/list_waiting"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="25dp"
android:paddingRight="25dp" >

<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:indeterminate="true" />

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/msg_waiting" />
</LinearLayout>

</LinearLayout>
txl.xml的代码如下:

<?xml version="1.0" encoding="utf-8"?>

<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:mode="twoLine"
>

<TextView android:id="@+id/txl1"
android:layout_width="match_parent"
android:textSize="@dimen/text_size_type_name"
android:layout_marginLeft="4dip"
android:layout_height="wrap_content"
android:layout_marginTop="6dip"
/>

<TextView android:id="@+id/txl2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@android:id/text1"
android:layout_alignStart="@android:id/text1"
android:textSize="@dimen/text_size_name"
android:layout_marginLeft="4dip"
/>

</TwoLineListItem>
activity的代码如下:

public class TxlActivity extends Activity implements JsonResultListener{
private TxlDao txldao;
private ListView mListView;
private View mListWaiting;
private View mListNoResult;
private static final int WHAT_QUERY = 1;
private static final String TAG = "TxlActivity";
private ListOfMapAdapter<String, Object> adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_txl);
txldao = new TxlDao(this);
findViews();
}

private void findViews() {
mListView = (ListView) findViewById(R.id.list);
mListWaiting = findViewById(R.id.list_waiting);
mListNoResult = findViewById(R.id.list_no_result);


}
@Override
protected void onStart() {
super.onStart();
try {
if (adapter == null || adapter.getCount() == 0) {
mListView.setVisibility(View.GONE);
mListNoResult.setVisibility(View.GONE);
mListWaiting.setVisibility(View.VISIBLE);
txldao.findtel(WHAT_QUERY, App.unitKey, this);
}
} catch (Exception e) {
Log.e(TAG, "出现异常", e);
}
}

@Override
protected void onStop() {
super.onStop();
}

public void onBackButtonClick(View view) {
this.finish();
}


@Override
public void onFailure(int what, JsonResult result, int statusCode,
String statusText) {
// TODO Auto-generated method stub
Toast.makeText(this, "出现错误: " + statusText +
"[code=" + statusCode + "]", Toast.LENGTH_SHORT).show();


}

@Override
public void onSuccess(int what, JsonResult result) {
switch (what) {
case WHAT_QUERY:
mListView.setVisibility(View.GONE);
mListWaiting.setVisibility(View.GONE);
mListNoResult.setVisibility(View.GONE);
if (result.get("success").booleanValue(false)) {
List<Map<String, Object>> data = result.get("results").listValue();
adapter = new ListOfMapAdapter<String, Object>(this,
R.layout.txl,
new int[]{R.id.txl1, R.id.txl2},
new String[]{"user_name","mobile_phone"}, data);

mListView.setAdapter(adapter);
mListView.setOnItemClickListener(new OnItemClickListener() {


@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {

Map<String, Object> map = (Map<String, Object>) parent.getAdapter().getItem(position);
String number=(String) map.get("MOBILE_PHONE");
Intent intent = new Intent();
intent.setAction("android.intent.action.CALL");
intent.setData(Uri.parse("tel:"+number));
startActivity(intent);

}

});
if (data == null || data.isEmpty()) {
Toast.makeText(this, R.string.msg_no_result, Toast.LENGTH_SHORT).show();
mListNoResult.setVisibility(View.VISIBLE);
} else {
mListView.setVisibility(View.VISIBLE);
}
} else {
Toast.makeText(this, result.get("message").stringValue(), Toast.LENGTH_SHORT).show();
mListNoResult.setVisibility(View.VISIBLE);
}
break;

default:
break;
}

}
}
我想要的结果是这样的背景是黑色的。像这样:


请问怎么做呢?


...全文
159 点赞 收藏 7
写回复
7 条回复

还没有回复,快来抢沙发~

发动态
发帖子
Android
创建于2009-10-09

4.6w+

社区成员

9.0w+

社区内容

移动平台 Android
社区公告
暂无公告