文章来源1:http://blog.csdn.net/janronehoo/article/details/7240241

listView.setCacheColorHint(0); 或者android:cacheColorHint="#00000000" 去除listview的拖动背景色

自定义listview的时候,当你不使用android:cacheColorHint="#00000000" 会出现下面选中一个空间黑色底色的情况,破坏整体美观度:

当你不使用android:listSelector属性,默认会显示选中的item为橙黄底色,有时候我们需要去掉这种效果:





  



listview 拖动 背景图 显隐    2013 - 07 -19

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30                   < ListView                  android:id = "@+id/recommand_app_list"                  android:layout_width = "fill_parent"                  android:layout_height = "fill_parent"                  android:layout_below = "@id/recommands_list_view_header_divider"                  android:fadingEdge = "none"                  android:scrollbars = "none"                  android:scrollingCache = "true"               ListView                                  < ListView                  android:id = "@+id/recommand_app_list"                  android:layout_width = "fill_parent"                  android:layout_height = "fill_parent"                  android:layout_below = "@id/recommands_list_view_header_divider"                  android:background = "@drawable/ic_content_bg_repeat"                  android:divider = "@drawable/ic_list_divider_repeat"                  android:dividerHeight = "1dp"                  android:fadingEdge = "none"                  android:persistentDrawingCache = "none"                  android:scrollbars = "none"                  android:scrollingCache = "false"                  android:smoothScrollbar = "true"               ListView >

ListView是一个经常要用到的android控件,现总结遇到过的一些美化的小细节。

1、listview在拖动的时候背景图片消失变成黑色背景,等到拖动完毕我们自己的背景图片才显示出来

解决:在XML中加入

android:scrollingCache="false" 或 android:cacheColorHint="#00000000"

2、listview的上边和下边有黑色的阴影

解决: android:fadingEdge="none"

3、修改listview的Item默认选择时的黄色背景

解决:在java文件中使用listview.setSelector()方法,或使用如下代码

1 android:listSelector= "#00000000"//这样写是透明的,也可加入Drawable图片

4、lsitview的每一项之间需要设置一个图片做为间隔

解决: android:divider=”@drawable/list_driver”

文章来源2: http://blog.csdn.net/liuhanhan512/article/details/7225989

去除ListView滑到顶部和底部时边缘的黑色阴影:

Xml代码  
  1. android:fadingEdge="none"  
[xml]  view plain copy
  1. android:fadingEdge="none"  

  

去除拖动时默认的黑色背景:

Xml代码  
  1. android:cacheColorHint="#00000000"  
[xml]  view plain copy
  1. android:cacheColorHint="#00000000"  

 

去除选中时的黄色底色:

Xml代码  
  1. android:listSelector="#00000000"  
[xml]  view plain copy
  1. android:listSelector="#00000000"  

去除行与行之间的黑线:

Java代码  
  1. msgList.setDivider(null);  
[java]  view plain copy
  1. msgList.setDivider(null);  

ListView刷新后自动滚到最底部:

Java代码  
  1. msgList.setSelection(msgList.getAdapter().getCount()-1);  
[java]  view plain copy
  1. msgList.setSelection(msgList.getAdapter().getCount()-1);  

 以上,自然也可以进行自定义颜色处理。

文章来源3: http://www.cnblogs.com/loulijun/archive/2012/04/15/2450312.html

Android美工坊--listview更改选中时item背景色

默认情况下使用ListView背景色是黑色,选中item的高亮颜色是菊黄色,很多时候不得不自己定义背景色或者背景图

android:cacheColorHint="@android:color/transparent",意思为去黑色底色,比如ListView滚动时会刷新界面,默认颜色还是系统颜色,所以采用这种方式设置其为透明即可,这个属性在ListView中使用圆角图片来设置ListView时很有用

android:divider="@null"用于去掉listview的item之间的黑线

1、背景色

即在list_item_color_bg.xml中通过设置color来实现点击item时不同的颜色,但是如果使用color的话,listview无法使用android:listSelector属性,如果设置android:listSelector方式的话,点击一个item后整体的ListView全部都会变成一种颜色,这时必须采用在item中设置android:background的方式才可以。android:listSelector方式适用于图片的方式,即类似与(android:drawable="@drawable/img")

<?xml version="1.0" encoding="utf-8"?><selector  xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_pressed="true" android:drawable="@color/green">item>    <item android:drawable="@color/white">item>selector>

color.xml

<?xml version="1.0" encoding="utf-8"?><resources>    <color name="white">#ffffffcolor>    <color name="black">#000000color>    <color name="green">#00ff00color>resources>

下面再看看布局文件

listview.xml,用color的方式,这里不能使用listSelector

复制代码
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    >    <ListView         android:id="@+id/lv"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:fastScrollEnabled="true"        android:cacheColorHint="@android:color/transparent"        android:divider="@null"        />LinearLayout>
复制代码

list_item_color.xml,通过color设置直接在item的布局中设置背景即可

复制代码
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="horizontal"    android:background="@drawable/list_item_color_bg">    <ImageView        android:id="@+id/img"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        />    <LinearLayout         android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:orientation="vertical"        >        <TextView            android:id="@+id/tv"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:textSize="20sp"        />        <TextView             android:id="@+id/info"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:textSize="14sp"            />    LinearLayout>LinearLayout>
复制代码

效果图

2、背景图

这种方式是在selector文件中采用图片来设置item的背景,无论是设置ListView的android:listSelector的方式还是设置item的android:background的方式都可以使用,不过最好还是使用android:background的方式,因为使用android:listSelector的方式时下面的selector文件中设置的默认时的图片

<item android:drawable="@drawable/login_input"/>)不会显示,而改为background的方式则可以。有些奇怪,希望懂的能指点一下

<?xml version="1.0" encoding="utf-8"?><selector  xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_pressed="true" android:drawable="@drawable/input_over"/>    <item android:drawable="@drawable/login_input"/>selector>

listView此时设置如下,这里在item中不设置android:background

复制代码
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    >    <ListView         android:id="@+id/lv"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:fastScrollEnabled="true"        android:cacheColorHint="@android:color/transparent"        android:listSelector="@drawable/list_item_drawable_bg"        />LinearLayout>
复制代码

此时的效果图如下:背景图是.9.png图片,注意默认的白色.9.png图片login_input没有显示

如果使用android:background的方式,取消android:listSelector的方式,效果如下


更多相关文章

  1. Android 5.1源代码与Nexus设备工厂镜像下载
  2. Android 自音乐播放器源代码
  3. Android Timer编写方式
  4. Android之fragment的两种创建方式
  5. Android WebView与 JS 的交互方式
  6. Android Jni代码示例讲解
  7. Android 多线程之synchronized锁住的是代码还是对象(二)
  8. Android有用代码片断(五)
  9. Android Wi-Fi EAP-SIM代码解析

随机推荐

  1. Android有未接来电后处理(判断未接来电)
  2. 解决android sdk无法更新 更新慢的问题
  3. Android(安卓)ListView滑动过程中图片显
  4. 解读Android之Intents和Intent Filters
  5. 淘宝Android自动化测试框架-TMTS
  6. Android修改系统时间(应用程序获得系统权
  7. Android(安卓)logcat命令详解
  8. Android.......移动创造生活
  9. 最简单的基于FFmpeg的移动端例子:Android(
  10. 修改Android解锁界面