Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make Tab Custom Layout?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 129
    Comment on it

    In the below example code, I have created a Tab Custom Layout. In Tab Layout I have added Text with icon. Here first I have created two custom tab layouts Then I have created a method setupTabIcons() and inflate Custom layouts for tabOne and tabTwo.  
    You can see below example code it clearly describes "How to make Tab Custom Layout?"

     

     
    Step(1)I have created First a setupTabIcons() method-

     private void setupTabIcons() {
    
                //inflate custom layout for tabOne
            View tabOne = (View) LayoutInflater.from(getActivity()).inflate(R.layout.custom_tab_myprofile, null);
            TextView view = (TextView) tabOne.findViewById(R.id.tab);
            ImageView view1 = (ImageView) tabOne.findViewById(R.id.img_male);
    
            //inflate custom layout for tabTwo
            View tabTwo = (View) LayoutInflater.from(getActivity()).inflate(R.layout.custom_tab_myprofile2, null);
            TextView v = (TextView) tabTwo.findViewById(R.id.tab2);
            ImageView v2 = (ImageView) tabTwo.findViewById(R.id.img_female);
    
            // position  tabs(tabOne,tabTwo)
            
            tabLayout.getTabAt(0).setCustomView(tabOne);
            tabLayout.getTabAt(1).setCustomView(tabTwo);
    
        }


    Step(2)-Created custom_tab_myprofile .xml layout for tabOne-

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:gravity="center"
        android:layout_height="wrap_content">
        <ImageView
            android:id="@+id/img_male"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/male"/>
      <TextView
        android:layout_toRightOf="@+id/img_male"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tab"
        android:text="Male"
        android:paddingLeft="5dp"
        android:textColor="#1e1d1d"
        android:textSize="20sp"/>
    </RelativeLayout>

    Step(3)-Created custom_tab_myprofile2 .xml layout for tabTwo-
     

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
       android:gravity="center"
        android:layout_height="wrap_content">
        <ImageView
            android:id="@+id/img_female"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/female"/>
        <TextView
            android:layout_toRightOf="@+id/img_female"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/tab2"
            android:text="Female"
            android:paddingLeft="5dp"
            android:textColor="#1d1c1c"
            android:textSize="20sp"/>
    </RelativeLayout>
    
    

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: