android - How to set FloatingActionButton Over the screen in Tabs Layout? -


in application want set floatingactionbutton on screen in tab's layout.

the floatingactionbutton want set this

in project have created firstly tablayout , viewpager , in last floatingactionbutton image

visit_tab.xml

    <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     xmlns:app="http://schemas.android.com/apk/res-auto"     tools:context="com.weal.sachin.omcom.tabfragment"     android:orientation="vertical">       <android.support.design.widget.tablayout         android:id="@+id/sliding_tabs_visit"         android:layout_width="match_parent"         android:layout_height="60dp"         app:tabtextcolor="#000"         style="@style/base.textappearance.appcompat.light.widget.popupmenu.large"         app:tabselectedtextcolor="#fff"         android:background="#c64c24"/>      <android.support.v4.view.viewpager         android:id="@+id/viewpager_visit"         android:layout_width="match_parent"         android:layout_height="0dp"         android:layout_weight="1"         android:background="@color/white"/>     <android.support.design.widget.floatingactionbutton         android:id="@+id/fab111"         android:layout_width="75dp"         android:layout_height="75dp"         android:layout_gravity="bottom|end"         android:backgroundtint="@color/cardview_dark_background"         android:layout_margin="@dimen/fab_margin"         android:src="@android:drawable/ic_input_add"/> </linearlayout> 

visit_tab.java

    package com.weal.sachin.omcom;  import android.os.bundle; import android.support.annotation.nullable; import android.support.design.widget.floatingactionbutton; import android.support.design.widget.tablayout; import android.support.v4.app.fragment; import android.support.v4.app.fragmentmanager; import android.support.v4.app.fragmentpageradapter; import android.support.v4.app.fragmenttransaction; import android.support.v4.view.viewpager; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup;   public class visittab extends fragment {     public static tablayout tablayout;     public static viewpager viewpager;     public static int int_items = 3 ;     android.support.v4.app.fragmentmanager mfragmentmanager;      view view;     @nullable     @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {         getactivity().settitle("visit");          getcurrentgpslocation gps = new getcurrentgpslocation(getactivity());         if (gps.cangetlocation()) {              // \n new line          }else {             // can't location             // gps or network not enabled             // ask user enable gps/network in settings             gps.showsettingsalert();         }         view x =  inflater.inflate(com.weal.sachin.omcom.r.layout.activity_visit_tab,null);         tablayout = (tablayout) x.findviewbyid(com.weal.sachin.omcom.r.id.sliding_tabs_visit);         viewpager = (viewpager) x.findviewbyid(com.weal.sachin.omcom.r.id.viewpager_visit);         viewpager. setoffscreenpagelimit(3);           viewpager.setadapter(new myadapter(getchildfragmentmanager()));          floatingactionbutton fab = (floatingactionbutton)x.findviewbyid(r.id.fab111);         fab.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                 fragmenttransaction t = getfragmentmanager().begintransaction();                 add_visit mfrag = new add_visit();                 t.replace(r.id.framelayout, mfrag);                 t.commit();             }         });          tablayout.setupwithviewpager(viewpager);           return x;      }     class myadapter extends fragmentpageradapter {         com.weal.sachin.omcom.todayvisit todayvisit;         home home;         updatesfragment updatesfragment;         public myadapter(fragmentmanager fm) {             super(fm);         }          /**          * return fragment respect position .          */          @override         public fragment getitem(int position)         {             switch (position){                 case 0 : return new todayvisit();                 case 1 : return new yesterdayvisit();                 case 2 : return new allvisit();             }             return null;         }          @override         public int getcount() {              return int_items;          }          /**          * method returns title of tab according position.          */          @override         public charsequence getpagetitle(int position) {              switch (position){                 case 0 :                     return "today";                 case 1 :                     return "yesterday";                 case 2 :                     return "visit all";             }             return null;         }     }  } 

in xml file floatinactionbutton displaying taking place of viewpager want set floatinactionbutton on viewpager.

got solutioin :-

little change in xml visit_tab.xml

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     xmlns:app="http://schemas.android.com/apk/res-auto"     tools:context="com.weal.sachin.omcom.tabfragment"     android:orientation="vertical">       <android.support.design.widget.tablayout         android:id="@+id/sliding_tabs_visit"         android:layout_width="match_parent"         android:layout_height="60dp"         app:tabtextcolor="#000"         style="@style/base.textappearance.appcompat.light.widget.popupmenu.large"         app:tabselectedtextcolor="#fff"         android:background="#c64c24"/>     <android.support.design.widget.coordinatorlayout         android:layout_width="match_parent"         android:layout_height="wrap_content">      <android.support.v4.view.viewpager         android:id="@+id/viewpager_visit"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:background="@color/white"/>         <android.support.design.widget.floatingactionbutton             android:id="@+id/fab111"             android:layout_width="75dp"             android:layout_height="75dp"             android:layout_gravity="bottom|end"             android:backgroundtint="@color/cardview_dark_background"             android:layout_margin="@dimen/fab_margin"             android:src="@android:drawable/ic_input_add"/>         </android.support.design.widget.coordinatorlayout>  </linearlayout> 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -