android:cacheColorHint=“#00000000”

本文总结了ListView控件在Android应用中的常见美化需求,包括解决拖动时背景消失的问题、移除默认的选择高亮颜色、消除边角阴影效果以及自定义Item间的分隔线。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

istView.setCacheColorHint(0); 或者Android:cacheColorHint="#000000" 去除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
<!-- 最后一条item所在的位置会闪烁 -->
    
             < 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
    
    
    
<!--修复问题: 最后一条item所在的位置会闪烁 -->
    
             < 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”


http://blog.youkuaiyun.com/liuhanhan512/article/details/7225989


FanHui.java:package com.videogo.ui.login;import android.content.Intent;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.Button;import com.videogo.openapi.EZOpenSDK;import ezviz.ezopensdk.R;import androidx.appcompat.app.AppCompatActivity;public class FanHui extends AppCompatActivity { private static final String TAG = “EZPreview”; private String mAppKey; private String mDeviceSerial; private String mVerifyCode; private String mAccessToken; private int mCameraNo; private static final String KEY_APPKEY = “appkey”; private static final String KEY_SERIAL = “serial”; private static final String KEY_VERIFYCODE = “VerifyCode”; private static final String KEY_ACCESSTOKEN = “accessToken”; private static final String KEY_CAMERANO = “cameraNo”; @Override protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.ez_playback_list_page); extractParametersFromIntent(); View fanHui = findViewById(R.id.fanhui); fanHui.setOnClickListener(v -> finish()); Button huifangBtn = findViewById(R.id.fanhui); huifangBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 创建Intent跳转到FanHui活动 Intent intent = new Intent(FanHui.this, MainActivity.class); // 传递必要参数(可选) intent.putExtra(“deviceSerial”, mDeviceSerial); intent.putExtra(“cameraNo”, mCameraNo); intent.putExtra(“accessToken”, mAccessToken); intent.putExtra(“appkey”, mAppKey); intent.putExtra(“verifyCode”, mVerifyCode); startActivity(intent); } }); } private void extractParametersFromIntent() { Bundle extras = getIntent().getExtras(); if (extras != null) { mAppKey = extras.getString(KEY_APPKEY, “”); mDeviceSerial = extras.getString(KEY_SERIAL, “”); mVerifyCode = extras.getString(KEY_VERIFYCODE, “”); mAccessToken = extras.getString(KEY_ACCESSTOKEN, “”); mCameraNo = extras.getInt(KEY_CAMERANO, 0); Log.d(TAG, “Received parameters:”); Log.d(TAG, “AppKey: " + mAppKey); Log.d(TAG, “DeviceSerial: " + mDeviceSerial); Log.d(TAG, “VerifyCode: " + mVerifyCode); Log.d(TAG, “AccessToken: " + mAccessToken); Log.d(TAG, “CameraNo: " + mCameraNo); } else { Log.e(TAG, “No parameters received from intent”); // 如果没有参数,可以显示错误信息并退出// finish(); } }} ez_playback_list_page.xml: <com.videogo.widget.TitleBar android:id=”@+id/title” android:layout_width=“match_parent” android:layout_height=“wrap_content”> </com.videogo.widget.TitleBar> <com.videogo.widget.TitleBar android:id=”@+id/pb_title_bar_landscape” android:layout_width=“match_parent” android:layout_height=“80dp” android:visibility=“gone” /> <com.videogo.widget.loading.LoadingView android:layout_width=“wrap_content” android:layout_height=“wrap_content” /> <com.videogo.widget.loading.LoadingView android:id=”@+id/remote_loading_iv" android:layout_width=“wrap_content” android:layout_height=“wrap_content” /> <com.videogo.widget.CheckTextButton android:id=“@+id/fullscreen_button” android:layout_width=“wrap_content” android:layout_height=“wrap_content” android:layout_alignParentRight=“true” android:layout_centerVertical=“true” android:layout_marginRight=“15dp” android:background=“@drawable/fullscreen_button_selector” /> <com.videogo.widget.loading.LoadingTextView android:id=“@+id/loadingTextView” android:layout_width=“match_parent” android:layout_height=“match_parent” android:layout_centerInParent=“true” android:background=“#efefef” android:visibility=“gone” /> <com.videogo.widget.PinnedHeaderListView android:id=“@+id/listView” android:layout_width=“match_parent” android:layout_height=“match_parent” android:layout_above=“@+id/delete_playback” android:cacheColorHint=“#00000000android:divider=“@null” android:dividerHeight=“0dp” android:fadingEdge=“vertical” android:listSelector=“@null” android:overScrollFooter=“@null” android:scrollbarAlwaysDrawVerticalTrack=“false” android:scrollingCache=“false” /> <com.videogo.widget.PinnedHeaderListView android:id=“@+id/listView_sdkcloud” android:layout_width=“match_parent” android:layout_height=“match_parent” android:layout_above=“@+id/delete_playback_sdkcloud” android:cacheColorHint=“#00000000android:divider=“@null” android:dividerHeight=“0dp” android:fadingEdge=“vertical” android:listSelector=“@null” android:overScrollFooter=“@null” android:scrollbarAlwaysDrawVerticalTrack=“false” android:scrollingCache=“false” /> <com.videogo.widget.PinnedHeaderListView android:id=“@+id/listView_device” android:layout_width=“match_parent” android:layout_height=“match_parent” android:layout_above=“@+id/delete_playback_device” android:cacheColorHint=“#00000000android:divider=“@null” android:dividerHeight=“0dp” android:fadingEdge=“vertical” android:listSelector=“@null” android:overScrollFooter=“@null” android:scrollbarAlwaysDrawVerticalTrack=“false” android:scrollingCache=“false” /> 在上述代码顶部标题栏位置添加一个居中的年月日日期显示模块并且在显示年月日旁边添加一个图片按钮路径为drawable目录中playback_more_down1.png,这个年月份日期模块默认显示当天的年月日并且点击旁边新添加的图片按钮后显示一个年月日的日期选择器,用户选择日期选择器的年月日更新显示这个年月日日期显示模块。
最新发布
06-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值