android - 如何增加选项卡小部件中选定的选项卡高度?

标签 android tabwidget

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.

关于android - 如何增加选项卡小部件中选定的选项卡高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29557957/

相关文章:

Android - View 无法在编辑模式下实例化。空指针异常

Android - 阻止 TalkBack 大声宣布 TextView 标题

java - 摆脱(隐藏)Android TabWidget 的 "Focused State"

android - 制作自定义标签按钮

android - 使用 XML 样式设置 AndroidPlot XYPlot 的样式

java - 重新创建 Activity 时 onActivityResult() 函数?

java - android自定义列表不显示

android - 在 android 中绘制 TabWidget 时的 NPE(仅在 HTC Magic 上?)

android - 将 TabHost 控件添加到 Linearlayout/在 tabhost 选项卡下添加布局

android - Holo Light Theme 的 Holo Dark TabWidget 样式