>将我的行中的按钮设置为不可聚焦
>通过代码和XML设置ListSelector(不是同时)
>尝试在OnItemClickListener中更改传递的VIEw的背景
>使用带有bot true和false参数的setItemsCanFocus()
>使用“selected”和“pressed”状态设置XML drawable到行布局根目录
自从我使用Toast测试后,检测到了点击.但我只是无法强制ListVIEw突出显示所选行
列表显示
<ListVIEw androID:ID="@androID:ID/List" androID:ListSelector="@drawable/List_selected" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:layout_below="@+ID/etbg" androID:choiceMode="singleChoice" androID:divIDer="@color/div" ></ListVIEw>
用作列表行的布局
<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"androID:layout_wIDth="match_parent"androID:layout_height="match_parent" ><TextVIEw androID:ID="@+ID/tvListItemArtist" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_centerVertical="true" androID:layout_marginleft="14dp" androID:focusable="false" androID:focusableIntouchMode="false" androID:text="Small Text" androID:layout_toRightOf="@+ID/tbListPlay" androID:textAppearance="?androID:attr/textAppearanceSmall" androID:textcolor="#FFFFFF" /><TextVIEw androID:ID="@+ID/tvListItemSong" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignBottom="@+ID/tvListItemArtist" androID:layout_centerVertical="true" androID:layout_marginleft="5dp" androID:layout_toRightOf="@+ID/tvListItemArtist" androID:focusable="false" androID:focusableIntouchMode="false" androID:text="Small Text" androID:textAppearance="?androID:attr/textAppearanceSmall" androID:textcolor="#FFFFFF" /><ImageVIEw androID:ID="@+ID/img_List_audio_saved" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignParentRight="true" androID:layout_centerVertical="true" androID:layout_marginRight="50dp" androID:src="@drawable/attention" androID:visibility="gone" /><button androID:ID="@+ID/tbListPlay" androID:layout_wIDth="40dp" androID:layout_height="40dp" androID:layout_alignParentleft="true" androID:layout_centerVertical="true" androID:layout_marginBottom="8dp" androID:layout_margintop="8dp" androID:background="@drawable/button_play" androID:focusable="false" androID:focusableIntouchMode="false" /> </relativeLayout>
有什么建议?
解决方法 在drawables文件夹中为列表视图创建一个选择器,并将列表项背景设置为此drawable.请参阅下面的代码select_button_background.xml
<?xml version="1.0" enCoding="utf-8"?><selector xmlns:androID="http://schemas.androID.com/apk/res/androID"> <item androID:drawable="@drawable/select_button_selected" androID:state_enabled="true" androID:state_pressed="true"/> <item androID:drawable="@drawable/select_button_selected" androID:state_enabled="true" androID:state_selected="true"/> <item androID:drawable="@drawable/select_button_selectable" androID:state_pressed="false"/> <item androID:drawable="@drawable/select_button_selectable" androID:state_selected="false"/> </selector>
select_button_selectable.xml
<?xml version="1.0" enCoding="utf-8"?><shape xmlns:androID="http://schemas.androID.com/apk/res/androID" > <gradIEnt androID:angle="270" androID:endcolor="#CCCCCC" androID:startcolor="#ddddDD" androID:type="linear" /> <corners androID:radius="10dp" /> <shape> <stroke androID:wIDth="1dp" androID:color="#333333" /> </shape></shape>
select_button_selected.xml
<?xml version="1.0" enCoding="utf-8"?><shape xmlns:androID="http://schemas.androID.com/apk/res/androID" > <gradIEnt androID:angle="270" androID:endcolor="#AAAAAA" androID:startcolor="#BBBBBB" androID:type="linear" /> <corners androID:radius="10dp" /> <shape> <stroke androID:wIDth="1dp" androID:color="#333333" /> </shape></shape>总结
以上是内存溢出为你收集整理的android ListView不会突出显示所选行全部内容,希望文章能够帮你解决android ListView不会突出显示所选行所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)