简体   繁体   中英

How to increase the selected tab height in tab widget?

I Followed the below code for changing the height of selected tab.But i didnt get as i expected.

 mTabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 90;
 mTabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 80;
 mTabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 80;
 mTabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 80;

For reference please view the below image which is my actual requirement. Tabwidget

First create a xml file bottom_tabs.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" >
     <android.support.v4.app.FragmentTabHost
       android:id="@android:id/tabhost"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:background="#FFFFFF" >

    <RelativeLayout
        android:id="@+id/linearLayoutTab"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="0" />

        <FrameLayout
            android:id="@+id/realtabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1" />

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="#00000000"
            android:tabStripEnabled="true" />
    </RelativeLayout>
</android.support.v4.app.FragmentTabHost>

Add the background image to tab icon like as:

mTabHost.getTabWidget().getChildAt(0)
            .setBackgroundResource(R.drawable.d_tab_bg_selector);

d_tab_bg_selector code:

<?xml version="1.0" encoding="utf-8"?>

<!-- Active tab -->
<item android:drawable="@drawable/d_pressed_state" android:state_focused="false" android:state_pressed="false" android:state_selected="true"/>
<!-- Inactive tab -->
<item android:drawable="@drawable/d_unpressed_state" android:state_focused="false" android:state_pressed="false" android:state_selected="false"/>
<!-- Pressed tab -->
<item android:drawable="@drawable/d_pressed_state" android:state_pressed="true"/>
<!-- Selected tab (using d-pad) -->
<item android:drawable="@drawable/d_unpressed_state" android:state_focused="true" android:state_pressed="false" android:state_selected="true"/>

d_pressed_state source code:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <solid android:color="#00000000" />
    </shape>
</item>
<item
    android:top="8dp">
    <shape android:shape="rectangle">
        <solid android:color="#009343" />
    </shape>
</item>
<item android:right="1dp" android:left="1dp">
    <shape android:shape="rectangle">
        <solid android:color="#000000" />
    </shape>
</item>

Write your own code for your unpressed state.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM