Java Android:FragmentTabHost小部件不显示标题
我正在尝试使用FragentTabHost设计一个自定义TabWidget,并遵循以下两个选项卡布局指南: Im构建FragmentTabHost有三个片段,第一个片段有一个可扩展的列表视图 一切正常,我可以设置背景颜色、图标(如果我愿意)和指示器,就像分隔符一样(如果我愿意),但是由于某种原因,选项卡标题没有出现,我找不到它不出现的原因 如果我从tab\u layout.xml中的android:background=“@drawable/tab\u indicator”中删除tab\u indicator.xml,并将backgroundcolor设置为选项卡标题显示的任何颜色,但我显然得不到指示器 有没有人知道我到底出了什么问题,遗漏了什么。我已经试着解决这个问题,搜索för几天了,它开始变得非常令人沮丧,因为它看起来很简单 tab_layout.xmlJava Android:FragmentTabHost小部件不显示标题,java,android,xml,Java,Android,Xml,我正在尝试使用FragentTabHost设计一个自定义TabWidget,并遵循以下两个选项卡布局指南: Im构建FragmentTabHost有三个片段,第一个片段有一个可扩展的列表视图 一切正常,我可以设置背景颜色、图标(如果我愿意)和指示器,就像分隔符一样(如果我愿意),但是由于某种原因,选项卡标题没有出现,我找不到它不出现的原因 如果我从tab\u layout.xml中的android:background=“@drawable/tab\u indicator”中删除tab\u
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/tab_indicator">
<TextView
android:id="@+id/tabText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center_vertical|center_horizontal"
android:textColor="@drawable/tab_text"
android:textSize="15dp"
/>
</LinearLayout>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states-->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected" />
<!-- Focused states-->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected" />
<!-- Pressed-->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_pressed" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_pressed" />
</selector>
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tabHost"
android:layout_gravity="center_horizontal"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="35dp"
android:showDividers="middle"
android:layout_weight="0"
android:orientation="horizontal"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
</FrameLayout>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:top="-7dp" android:bottom="0dp" android:left="-7dp" android:right="-7dp">
<shape
android:shape="rectangle">
<padding android:left="10dp"
android:top="15dp"
android:right="10dp"
android:bottom="15dp" />
<stroke android:width="4dp" android:color="#FF00ccff" />
<solid android:color="#2fff00"
/>
</shape>
</item>
</layer-list>
tab_indicator.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/tab_indicator">
<TextView
android:id="@+id/tabText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center_vertical|center_horizontal"
android:textColor="@drawable/tab_text"
android:textSize="15dp"
/>
</LinearLayout>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states-->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected" />
<!-- Focused states-->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected" />
<!-- Pressed-->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_pressed" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_pressed" />
</selector>
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tabHost"
android:layout_gravity="center_horizontal"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="35dp"
android:showDividers="middle"
android:layout_weight="0"
android:orientation="horizontal"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
</FrameLayout>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:top="-7dp" android:bottom="0dp" android:left="-7dp" android:right="-7dp">
<shape
android:shape="rectangle">
<padding android:left="10dp"
android:top="15dp"
android:right="10dp"
android:bottom="15dp" />
<stroke android:width="4dp" android:color="#FF00ccff" />
<solid android:color="#2fff00"
/>
</shape>
</item>
</layer-list>
活动\u main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/tab_indicator">
<TextView
android:id="@+id/tabText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center_vertical|center_horizontal"
android:textColor="@drawable/tab_text"
android:textSize="15dp"
/>
</LinearLayout>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states-->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected" />
<!-- Focused states-->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected" />
<!-- Pressed-->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_pressed" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_pressed" />
</selector>
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tabHost"
android:layout_gravity="center_horizontal"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="35dp"
android:showDividers="middle"
android:layout_weight="0"
android:orientation="horizontal"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
</FrameLayout>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:top="-7dp" android:bottom="0dp" android:left="-7dp" android:right="-7dp">
<shape
android:shape="rectangle">
<padding android:left="10dp"
android:top="15dp"
android:right="10dp"
android:bottom="15dp" />
<stroke android:width="4dp" android:color="#FF00ccff" />
<solid android:color="#2fff00"
/>
</shape>
</item>
</layer-list>
tab_selected.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/tab_indicator">
<TextView
android:id="@+id/tabText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center_vertical|center_horizontal"
android:textColor="@drawable/tab_text"
android:textSize="15dp"
/>
</LinearLayout>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states-->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected" />
<!-- Focused states-->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected" />
<!-- Pressed-->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_pressed" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_pressed" />
</selector>
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tabHost"
android:layout_gravity="center_horizontal"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="35dp"
android:showDividers="middle"
android:layout_weight="0"
android:orientation="horizontal"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
</FrameLayout>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:top="-7dp" android:bottom="0dp" android:left="-7dp" android:right="-7dp">
<shape
android:shape="rectangle">
<padding android:left="10dp"
android:top="15dp"
android:right="10dp"
android:bottom="15dp" />
<stroke android:width="4dp" android:color="#FF00ccff" />
<solid android:color="#2fff00"
/>
</shape>
</item>
</layer-list>
解决了这个问题,如果我在FragmentTabHost和TabWidget中更改android:layou\u高度,它会显示文本,就这么简单。但在我看来,高度太大了^^我希望它像35dp一样小一些,如果我改变tab_selected.xml中的填充,取消选中并按下,然后我可以改变TabWidget activity_main.xml中的高度,否则文本就不适合这个选项卡。解决了这个问题,如果我在FragmentTabHost和TabWidget中更改android:layout\u height,它会显示文本,就这么简单。但在我看来,高度太大了^^^我希望它像35dp一样小,如果我改变tab_selected.xml中的填充,取消选中并按下,然后我可以改变TabWidget activity_main.xml中的高度,就可以了,否则文本就不适合这个选项卡