1

我的应用程序中有 2-3 个活动,它们都在内存池中共享数据。我希望能够在这些活动之间轻松切换,同时保持它们同时运行。另外,我正在为 Android 4.0 开发。我想使用TabActivity,但它已被弃用并替换为ActionBar,我已经尝试过,但我认为这不是我想要的。我想要大标签,类似于在股票 Android 音乐应用程序中找到的经典“艺术家/播放列表/所有”标签,或者像下面屏幕截图底部的标签栏。有谁知道创建这些选项卡的库或一种ActionBar更可定制的方法?或者正在使用TabActivity一个非常好的解决方案,即使是在 ICS 设备上?

在此处输入图像描述

4

3 回答 3

1

实际上,ActionBar 是您正在寻找的。

您应该将您的活动转换为片段。假设它们不是太复杂,这应该不难。那里有很多例子。您需要一个 Activity,最好是一个 ActivityFragmentActivity来保存所有这些。

这应该有助于:

http://arvid-g.de/12/android-4-actionbar-with-tabs-example

于 2012-07-30T22:43:22.357 回答
1

这有几个子问题,我将尝试解决所有问题:

- 为了使用顶部选项卡,您需要使用 ActionBar。

- 如果您要按照音乐应用程序的样式进行操作,您可以在视图之间横向滑动,并且当前视图的标签始终位于前面和中间......为此,您要使用的类称为ViewPager

您可以通过在 eclipse 中创建一个新的 Activity 并通过向导来查看所有这些方法。在“导航类型”下,您可以选择“标签”、“标签 + 滑动”、“滑动视图 + 标题条”。创建这些活动中的任何一个以查看其外观,然后查看代码以了解其实现方式以及如何对其进行自定义。

-不鼓励沿底部导航- 请参阅Android 设计指南,指定“不要使用底部标签栏”部分

于 2012-07-30T22:48:43.620 回答
1

您现在可能已经找到了答案,但我想我会分享另一种方法,您可以使用图像和 xml 创建类似标签栏的内容:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"        
    android:orientation="vertical"
    android:id="@+id/main">

    <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"        
        android:orientation="horizontal"
        android:background="@drawable/tabackground"
        android:layout_alignParentBottom="true"
        android:id="@+id/llBottom">

        <ImageButton 
            android:src="@drawable/icon2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#00000000"
            />

        <ImageButton 
            android:src="@drawable/icon3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#00000000"
            />

        <ImageButton 
            android:src="@drawable/icon4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#00000000"
            />

        <ImageButton 
            android:src="@drawable/icon5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#00000000"
            />        


    </LinearLayout>

    <ImageView         
        android:layout_height="24dp"
        android:layout_width="fill_parent"
        android:layout_alignTop="@+id/llBottom"       
        android:background="#10ffffff"/>

    <ImageView         
        android:layout_height="1dp"
        android:layout_width="fill_parent"
        android:layout_alignTop="@+id/llBottom"       
        android:background="#30ffffff"/>

</RelativeLayout>

在此处输入图像描述

并不完美,但有一些创造力和改变一些价值观,它看起来会非常好。

希望它在某种程度上有所帮助。

于 2012-07-31T00:19:58.683 回答