Android custom tab

Source: Internet
Author: User

Android custom tab

 

First, let's take a look at the layout file of the implementation tab.

 

 

 

The first FrameLayout is the container of the tab content.

The following TabView is a tab container.

Then look at the Activity:

 

Import sunger. widget. tabView; import sunger. widget. tabView. onTabItemClick; import android. OS. bundle; import android. support. v4.app. fragmentActivity; import android. support. v4.app. fragmentTransaction; import android. view. window; import com. sunger. tab_wechat.R; public class MainActivity extends FragmentActivity implements OnTabItemClick {private String [] mTitle = {, Address Book, found, I}; private int [] mIconSelect = {R. drawable. al _, R. drawable. al8, R. drawable. alb, R. drawable. ald}; private int [] mIconNormal = {R. drawable. ala, R. drawable. al9, R. drawable. c, R. drawable. ale}; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); requestWindowFeature (Window. FEATURE_NO_TITLE); setContentView (R. layout. activity_main); TabView tabView = (TabView) findViewById (R. id. id_tab); // tabView. setmPadding (7); // tabView. setmTextSize (12); // tabView. setmTextColorSelect (0xff45c01a); // tabView. setmTextColorNormal (0xff777777); // tabView. setBackgroundColor (Color. WHITE); tabView. setTitles (mTitle); tabView. setIconNormalIds (mIconNormal); tabView. setIconSeletedIds (mIconSelect); tabView. setOnTabItemClick (this); tabView. build (); tabView. setCurrentItem (0); setCurrentItem (1) ;}@ Overridepublic void onClick (int position) {// here you can set refresh or click the current tab to do not operate setCurrentItem (position );} public void setCurrentItem (int position) {FragmentTransaction transaction = getSupportFragmentManager (). beginTransaction (); transaction. replace (R. id. holder, new WeChatFragment (); transaction. commit ();}}


 

The UI effect is the same as that of the tab, but it cannot slide left or right. I will not lie to you if I study much.


 

Related Article

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.