Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom TabLayout with rounded corners

Tags:

android

I want to create a tablayout like this:

enter image description here

As you can see, i have rounded corners for tab layout background. I tried following code:

<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/tabs2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabIndicatorColor="#CECECF"
    app:tabBackground="@drawable/tab_bar_bg"
    app:tabMode="fixed"
    app:tabGravity="fill"/>

And result:

enter image description here

Is there a way to achive this rounded corners with tablayout? If answer is yes then what is my roadmap?

Ps: Don't mind the icons or icon colors on screenshot.

like image 609
Tolgay Toklar Avatar asked Nov 02 '25 11:11

Tolgay Toklar


1 Answers

Add this file to your drawable directory and add it to as background in your custom tab layout.

shape.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <corners
        android:bottomLeftRadius="16dp"
        android:bottomRightRadius="16dp"
        android:radius="32dp"
        android:topLeftRadius="16dp"
        android:topRightRadius="16dp" />

    <solid android:color="@color/tab_color" />

    <padding
        android:bottom="0dp"
        android:left="0dp"
        android:right="0dp"
        android:top="0dp" />

    <size
        android:height="32dp" />


</shape>
like image 82
Pawan Singh Chauhan Avatar answered Nov 04 '25 02:11

Pawan Singh Chauhan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!