
我的代码是:
ListContacts.java
public class ListContacts extends ListActivity { @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); System.out.println("List Contacts : onCreate : ");Cursor cursor = getContentResolver().query( ContactsContract.Contacts.CONTENT_URI, null, ContactsContract.Contacts.HAS_PHONE_NUMBER + " = 1", null, "UPPER(" + ContactsContract.Contacts.disPLAY_name + ") ASC"); startManagingCursor(cursor);ImageCursorAdapter .java
public class ImageCursorAdapter extends SimpleCursorAdapter implements SectionIndexer{public VIEw getVIEw(int pos, VIEw inVIEw, VIEwGroup parent) { VIEw v = inVIEw; String phoneNumber = null; String contactID = null; // Associate the xml file for each row with the vIEw if (v == null) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = inflater.inflate(R.layout.contact_ListvIEw, null); } this.c.movetoposition(pos); /** * Get the strings with the name and number of the person that the * current row */ // String lname = this.c.getString(this.c .getColumnIndex(EMPLOYEE_name))} }ListvIEw.xml
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="horizontal" androID:layout_wIDth="fill_parent" androID:paddingleft="5dp" androID:paddingRight="5dp" androID:layout_height="fill_parent" androID:background="@drawable/ListvIEw_bac"> <linearLayout androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:layout_marginRight="4dp" androID:orIEntation="horizontal"> <ImageVIEw androID:ID="@+ID/callimage" androID:layout_wIDth="36dp" androID:layout_height="49dp" androID:clickable="true" androID:background="@androID:color/transparent" androID:paddingRight="4dp" androID:src="@drawable/phone"> </ImageVIEw> <linearLayout androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:layout_gravity="center" androID:orIEntation="horizontal" > <TextVIEw androID:ID="@+ID/contact_name" androID:textcolor="@color/black" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:ellipsize="marquee" androID:textAppearance="?androID:attr/textAppearanceLarge" /> <ImageVIEw androID:ID="@+ID/favimage" androID:layout_wIDth="20dp" androID:layout_height="20dp" androID:layout_gravity="top|right" androID:background="@androID:color/transparent" androID:src="@drawable/favorites" androID:visibility="gone"> </ImageVIEw> <!-- <TextVIEw androID:ID="@+ID/contact_number" androID:textcolor="@color/black" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:paddingtop="2dp" androID:textAppearance="?androID:attr/textAppearanceSmall" /> --> </linearLayout> </linearLayout></linearLayout>解决方法:
添加一个xml文件来管理linearLayout的背景.
List_bg_selector.xml:
<?xml version="1.0" enCoding="utf-8"?><selector xmlns:androID="http://schemas.androID.com/apk/res/androID"> <!-- Active tab --> <item androID:state_selected="true" androID:state_focused="false" androID:state_pressed="false" androID:drawable="@drawable/List_selected_bgimage" /> <!-- Inactive tab --> <item androID:state_selected="false" androID:state_focused="false" androID:state_pressed="false" androID:drawable="@drawable/List_default_bgimage" /> <!-- pressed tab --> <item androID:state_pressed="true" androID:drawable="@drawable/List_selected_bgimage" /> <!-- Selected tab (using d-pad) --> <item androID:state_focused="true" androID:state_selected="true" androID:state_pressed="false" androID:drawable="@drawable/List_selected_bgimage" /></selector> 要管理文本颜色,请将文本颜色设置为其他xml.
text_selector.xml:
<?xml version="1.0" enCoding="utf-8"?><selector xmlns:androID="http://schemas.androID.com/apk/res/androID"> <item androID:state_selected="true" androID:color="@androID:color/black"/> <item androID:state_focused="true" androID:color="@androID:color/black"/> <item androID:state_pressed="true" androID:color="@androID:color/black"/> <item androID:color="@androID:color/white"/></selector> 总结 以上是内存溢出为你收集整理的更改焦点上的listview的背景图像全部内容,希望文章能够帮你解决更改焦点上的listview的背景图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)