首页 > 代码库 > ListView ViewPager ScrollView 修改边界色
ListView ViewPager ScrollView 修改边界色
如果觉得android中默认的listview 滑动到上面或者底部的阴影色不好看,可以这么定义
先看效果图
public class ListView extends android.widget.ListView { private OnScrollListener mLegacyOnScrollListener; private final MulticastOnScrollListener mMulticastOnScrollListener = new MulticastOnScrollListener(); public ListView(Context context) { this(context, null); } public ListView(Context context, AttributeSet attrs) { this(context, attrs, android.R.attr.listViewStyle); } public ListView(Context context, AttributeSet attrs, int defStyle) { super(new ContextWrapperEdgeEffect(context), attrs, defStyle); init(context, attrs, defStyle); } private void init(Context context, AttributeSet attrs, int defStyle) { int color = context.getResources().getColor(R.color.default_edgeeffect_color); if (attrs != null) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.EdgeEffectView, defStyle, 0); color = a.getColor(R.styleable.EdgeEffectView_edgeeffect_color, color); a.recycle(); } setEdgeEffectColor(color); } public void setOnScrollListener(OnScrollListener listener) { if (listener != null) { checkPrecondition(mLegacyOnScrollListener == null); mLegacyOnScrollListener = listener; addOnScrollListener(mLegacyOnScrollListener); } else if (mLegacyOnScrollListener != null) { removeOnScrollListener(mLegacyOnScrollListener); mLegacyOnScrollListener = null; } } public void setEdgeEffectColor(int edgeEffectColor) { ((ContextWrapperEdgeEffect) getContext()).setEdgeEffectColor(edgeEffectColor); } public void addOnScrollListener(OnScrollListener listener) { mMulticastOnScrollListener.add(listener); } public void clearOnScrollListeners() { mMulticastOnScrollListener.clear(); } public void removeOnScrollListener(OnScrollListener listener) { mMulticastOnScrollListener.remove(listener); } void checkPrecondition(boolean state) { if (!state) { throw new IllegalStateException(); } } }在xml中直接使用就可以
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".ListViewActivity"> <uk.co.androidalliance.edgeeffectoverride.ListView android:id="@+id/listview" android:layout_width="match_parent" android:layout_height="match_parent" app:edgeeffect_color="@color/green"/> </RelativeLayout>自定义属性文件
<?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="EdgeEffectView"> <attr name="edgeeffect_color" format="color"/> </declare-styleable> </resources>
Viewpager scrollview等类似
参考Demo 下载地址
ListView ViewPager ScrollView 修改边界色
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。