imnitesh
imnitesh

Reputation: 83

There is a gap between android action bar and tabs. why?

I have created custom layout for actionbar which has Tabview. But there is a gap between action bar and tabs in black. Kindly see the below image. I am using theme Theme.AppCompat.Light.DarkActionBar Target SDK: 19 Please help.

style.xml is as below:

<!-- Application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="actionBarSize">36dip</item>
    </style>

activity_main.xml

<LinearLayout 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:orientation="vertical">

<android.support.design.widget.TabLayout
    android:id="@+id/sliding_tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:theme="@style/MyCustomTabLayout"
    app:tabBackground="@android:color/holo_orange_dark"
    app:tabIndicatorColor="@android:color/holo_green_dark"
    app:tabTextColor="@android:color/white"
    app:tabSelectedTextColor="@android:color/black"/>

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="0px"
    android:layout_weight="1"
    android:background="@android:color/white" />

custom action bar

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_orange_dark">
<Spinner
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/spinnerActionBar" />

Upvotes: 1

Views: 1307

Answers (2)

Peanuts
Peanuts

Reputation: 352

I remember having this trouble before. Try adding the contentInsets in the xml.

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    ...
    app:contentInsetStart="0dp"
    app:contentInsetEnd="0dp"    
/>

Upvotes: 0

Sanket Kachhela
Sanket Kachhela

Reputation: 10856

Try to use Toolbar as ActionBar is deprecate now. you can have more functionality than ActionBar.

here is example like you need to use

Upvotes: 1

Related Questions