ListView ViewPager ScrollView modifies the boundary color, viewpagerscrollview

Source: Internet
Author: User

ListView ViewPager ScrollView modifies the boundary color, viewpagerscrollview

If it is difficult to see the shadow color of the default listview sliding to the top or bottom of android, you can define it as follows:

First look


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();        }    }}
You can directly use it in 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>
Custom property File

<?xml version="1.0" encoding="utf-8"?><resources>    <declare-styleable name="EdgeEffectView">        <attr name="edgeeffect_color" format="color"/>    </declare-styleable></resources>

Similar to Viewpager scrollview

Refer to Demo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.