Android implements the top navigation indicator imitating Netease News

We know that the page navigator is used in almost all projects. Usually, in order to save time, we will directly use other people's open source projects on GitHub. Recently, I was reviewing the custom view and tried to package it. The source code reference project pagerslidingtabstrip

Let's take a look at the renderings first

Text based page navigator

Image based page navigator

usage method

The main steps are divided into three steps

1) In the XML file

2) Find the corresponding control in the code

3) Initialize the adapter of viewpager and bind mviewpager to our mpagerindicator

matters needing attention,

For text title navigation, we only need to rewrite the getpagetitle method in the adapter

If it is icon navigation, our adapter needs to implement this excuse tabpagerindicator Icontabprovider and override the public int getpageiconresid (int position) method

We can set different slide line styles through setindicatormode (indicatormode)

For underline color, font color and size settings, please refer to the source code settings, which are not listed here

Let's take a look at the source code first

The idea can be divided into the following steps

1) Initialize all kinds of work in the construction method, including some custom properties, brushes, etc

2) Use the setviewpager () method to associate the control with the viewpager

3) Draw different underline styles according to different modes in OnDraw

4) When the viewpager slides, the corresponding method will be called to refresh the interface, because we added a pagelistener listener to the viewpager when we set it

The above is the top navigation indicator of Android imitation Netease News introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>