Skip to content Skip to sidebar Skip to footer

How To Set Tab Widget Indicator's Height In Android?

I want to reduce the height of selected tab indicator, I have used 9 patch image for it. Can you please let me know if you have any idea for the same ? Thanks.

Solution 1:

I used this code:

<!-- Focused states --><itemandroid:state_focused="true"android:state_selected="false"android:state_pressed="false"android:drawable="@drawable/tab_unselected_focused_example" /><itemandroid:state_focused="true"android:state_selected="true"android:state_pressed="false"android:drawable="@drawable/tab_selected_focused_example" /><!-- Pressed --><!--    Non focused states --><itemandroid:state_focused="false"android:state_selected="false"android:state_pressed="true"android:drawable="@drawable/tab_unselected_pressed_example" /><itemandroid:state_focused="false"android:state_selected="true"android:state_pressed="true"android:drawable="@drawable/tab_selected_pressed_example" /><!--    Focused states --><itemandroid:state_focused="true"android:state_selected="false"android:state_pressed="true"android:drawable="@drawable/tab_unselected_pressed_example" /><itemandroid:state_focused="true"android:state_selected="true"android:state_pressed="true"android:drawable="@drawable/tab_selected_pressed_example" />

and 9 patch images put in drawable, now it works perfectly.

Solution 2:

I use a different way of achieving custom design on tabs , create two xml files like this

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"android:gravity="center"android:layout_weight="1"android:background="@drawable/tab_selector"
><TextViewandroid:id="@+id/textView2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Friends"android:textColor="@drawable/tab_text_selector"
    />

When you set the indicator while adding a tab , use setIndicator(View view) pass this view after inflating it . This way you can achieve any custom design for tabs

Create selector files for changing background or text color on the basis of state.

Solution 3:

You need to create custom layout file for highlighted and non-highlighted tabs

Solution 4:

Try tabIndicatorHeight attribute. e.g. app:tabIndicatorHeight="1dp". There's also a nice write-up of it here: http://panavtec.me/playing-with-the-new-support-tablayout.

Post a Comment for "How To Set Tab Widget Indicator's Height In Android?"