0

I'm trying to remove the divider between the ActionBar and the tabs but I did not succeed yet. I've tried below code and i am getting result like my below image

can some one help me please how can i remove this line

code:-

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.TabLayout
            android:id="@+id/tabPatient"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabGravity="fill"
            app:tabMode="fixed" />
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>

enter image description here

Krish
  • 4,166
  • 11
  • 58
  • 110

2 Answers2

0

you should do like this:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="fixed"
        app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"  />

and in your java code:

        toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    viewPager = (ViewPager) findViewById(R.id.viewpager);
    setupViewPager(viewPager);

    tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);

also you have to insert the dependencies in build.gradle file but if you don't know how to implement it ask me

masoud vali
  • 1,528
  • 2
  • 18
  • 29
  • how can i implement depedencies ? – Krish Nov 19 '16 at 04:52
  • add ` compile 'com.android.support:appcompat-v7:23.0.1' compile 'com.android.support:design:23.0.1'` to your build.gradle file in its dependency section – masoud vali Nov 19 '16 at 04:57
  • yes off-course i am using compile 'com.android.support:appcompat-v7:24.2.1' and compile 'com.android.support:design:24.2.1' – Krish Nov 19 '16 at 04:59
  • tabLayout = (TabLayout) view.findViewById(R.id.tabPatient); viewPager = (ViewPager) view.findViewById(R.id.view_pager); tabLayout.setBackgroundResource(R.color.colorPrimary); tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#ffffff")); tabLayout.setTabTextColors(Color.parseColor("#727272"), Color.parseColor("#ffffff")); – Krish Nov 19 '16 at 05:04
  • in my java code i done nothing just added Color programatically – Krish Nov 19 '16 at 05:05
  • i saw that you didn't add toolbar in your updated xml code, you have to add it – masoud vali Nov 19 '16 at 05:07
  • According to my requirement ToolBar i have added on My Base Activity Xml file and This Tabs need to add on my child fragment xml file – Krish Nov 19 '16 at 05:09
  • i hope u understand – Krish Nov 19 '16 at 05:10
0

replace your tablayout with this structure:

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/p_toolbar"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@color/bar_color"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

    <android.support.design.widget.TabLayout
    android:id="@+id/tabPatient"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabGravity="fill"
    app:tabIndicatorHeight="4dp"
    app:tabMode="fixed"
    style="@style/Tab"
    app:tabTextAppearance="?android:textAppearanceMedium">
    </android.support.design.widget.TabLayout>

</android.support.design.widget.AppBarLayout>

a more better option will be to use all of this in a CoordinatorLayout and then include your main layout in it...

sharan
  • 226
  • 1
  • 4
  • 12