片段之间的Android选项卡导航

片段之间的Android选项卡导航,android,android-fragments,tabs,navigation,Android,Android Fragments,Tabs,Navigation,我想知道以下屏幕中的这些导航选项卡是如何实现的: 由于这些导航选项卡用于手机的多个菜单,因此它应该是标准的android布局项。 他们使用了FragmentTabHost吗?如果是,您如何能够像这样标记所选选项卡?我刚刚找到了用下划线标记所选选项卡的解决方案 如果有人能提供解释或教程链接,那就太好了 提前感谢。您需要创建一个xml文件,如下所示: <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="ht

我想知道以下屏幕中的这些导航选项卡是如何实现的:

由于这些导航选项卡用于手机的多个菜单,因此它应该是标准的android布局项。 他们使用了FragmentTabHost吗?如果是,您如何能够像这样标记所选选项卡?我刚刚找到了用下划线标记所选选项卡的解决方案

如果有人能提供解释或教程链接,那就太好了


提前感谢。

您需要创建一个xml文件,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>
    </LinearLayout>
</TabHost>
最后,您需要为每个选项卡创建两个文件(xml和类):

public class KontactActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.kontacte_layout);
    }
}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <TextView android:text="Contacts here"
            android:padding="15dip"
            android:textSize="18dip"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>

</LinearLayout>
公共类活动扩展活动{
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.Kontact_布局);
}
}

所以几天前我找到了解决方案。我使用本教程实现了以下几种选项卡:

有很多类似的教程,但是如果你使用的是Holo.Light主题,那么这个主题就有一个问题,这个主题很少被提及。问题在于,图像不会显示在选项卡中,而您只能看到文本

为了解决这个问题,我必须确保在style.xml中包含这个主题的Tab.Widget:

<style name="MyAppTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:tabWidgetStyle">@android:style/Widget.TabWidget</item>
</style>

@android:style/Widget.TabWidget
现在,即使我使用Holo.Light,标签的图像也会显示出来。如果您使用的是Theme.Black或Light,顺便说一下,这个问题不应该出现

多亏了Andrei Buneyeu对这个老问题的回答,我找到了这个解决方案:

我将使用下面的教程创建类似的内容:谢谢,但是TabActivity不推荐使用。我找到了一个用于碎片活动的解决方案,但这不适用于Android>4.0,因为图像不会显示在选项卡上。为了解决这个问题,我制作了一个带有Image+文本的自定义Tab.xml,然后图像就会显示出来,就像下面这个公认的答案所建议的那样:。但这导致了另一个问题。选择不再有效。导航正常,但您看不到选择了哪个选项卡。有人对此有解决方案吗?您尝试过使用appcompat吗?是的,谢谢。由于Tabhost已被弃用,我不想使用它,但您的回答仍然引导我朝着正确的方向前进,谢谢。不过,我不能推翻你的答案,因为我还没有15点声誉积分,对不起。
public class KontactActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.kontacte_layout);
    }
}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <TextView android:text="Contacts here"
            android:padding="15dip"
            android:textSize="18dip"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>

</LinearLayout>
<style name="MyAppTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:tabWidgetStyle">@android:style/Widget.TabWidget</item>
</style>