Android 无需 activity 使用选项卡查看

Android View with Tabs without having an activity

我有一个后台服务 运行,将一些视图显示为 system_overlay 以提供当前活动应用程序的附加信息。

要配置 HUD 显示,我想向用户显示另一个覆盖视图以更改一些参数。

设置视图也使用 system_overlay 的目的是不要激活 activity。否则,我提供信息的原始 activity 有时会在显示设置视图时被系统关闭,因为这个其他应用程序使用了大量的内存 (这就是为什么我不想在设置视图中使用 activity)


问题: 我想要在我的设置视图中带有 ViewPager 的 TabHost 之类的东西,但没有 activity。

即使我让 ViewPager 工作,我也无法加载内容,因为它们目前只能作为片段使用。


问题: 据我了解,没有 activity 片段将无法工作,那么完成这样的事情的正确方法是什么?

在您要为视图扩充的 xml 文件中,将它们都添加到该 xml 布局中,而不是将其他内容用于选项卡视图。

  <com.astuetz.PagerSlidingTabStrip
    android:id="@+id/tabs"
    app:pstsShouldExpand="true"
    app:pstsTextAllCaps="true"
    app:pstsIndicatorColor="#ff9900"
    android:textColor="#ffffff"
    android:textSize="14sp"
    app:pstsUnderlineColor="@android:color/white"
    android:layout_width="match_parent"
    android:layout_height="48dp">
</com.astuetz.PagerSlidingTabStrip>

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white" />

在您的 gradle 依赖项中添加此行:- 编译 'com.astuetz:pagerslidingtabstrip:1.0.1'

试一试,希望能解决你的问题。