重复动作条选项卡(S)与自定义视图 [英] replicate ActionBar Tab(s) with custom view

查看:93
本文介绍了重复动作条选项卡(S)与自定义视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有自定义导航,其中的自定义视图看起来像标准动作栏选项卡的动作条。我知道这听起​​来像重新发明轮子,但它意味着我们可以在同一行选项卡菜单按钮,如下图所示。这是一个设计要求,切实让更多的用户界面感觉这个应用程序比标准的Andr​​oid行为。

I would like to have an ActionBar with custom navigation where the custom views look like the standard action bar tabs. I know it sounds like reinventing the wheel but it means we can have the menu button on the same row as the tabs as shown below. This is a design requirement and practically makes much more UI sense for this app than the standard android behaviour.

我用从ActionBarSherlock的IcsLinearLayout试过像这样:

I've tried using an IcsLinearLayout from ActionBarSherlock like so:

<IcsLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:orientation="horizontal"
          android:layout_height="50dip">
         <Button
             android:id="@+id/tab_1"
             android:layout_height="match_parent"
             android:gravity="center"
             android:layout_width="wrap_content"
             android:textStyle="bold"
             android:text="TAB_1"
             android:background="@drawable/abs__item_background_holo_light"
             />
        <Button
            android:id="@+id/tab_2"
            android:layout_height="match_parent"
            android:gravity="center"
            android:layout_width="wrap_content"
            android:textStyle="bold"
            android:text="TAB_2"
            android:background="@drawable/abs__item_background_holo_light"
             />
</IcsLinearLayout>

不过,复制ActionButtons,我不知道如何复制选项卡。

But that replicates ActionButtons and I have no idea how to replicate Tabs.

我想我需要:

  • 在一个特殊的标签容器的ViewGroup(可能是从 ActionBarSherlock库)
  • 的意见看起来像标签用 从ABS库后台资源。
  • 在一些code,表明 该观点被点击后,保持选中状态(类似于 单选按钮)。
  • a special tab container viewgroup (probably from the ActionBarSherlock library)
  • views which look like tabs with a background resource from the ABS library.
  • some code to indicate that after the view is clicked it remains selected (similar to a RadioButton).

任何指针(即使在ActionBarSherlock库)的样本或类似的解决方案将大大AP preciated。

Any pointers to samples or similar solutions (even within the ActionBarSherlock library) would be greatly appreciated.

推荐答案

//使嵌入式标签

//pre-ICS
if (actionBarSherlock instanceof ActionBarImpl) {
    enableEmbeddedTabs(actionBarSherlock);

//ICS and forward
} else if (actionBarSherlock instanceof ActionBarWrapper) {
    try {
        Field actionBarField = actionBarSherlock.getClass().getDeclaredField("mActionBar");
        actionBarField.setAccessible(true);
        enableEmbeddedTabs(actionBarField.get(actionBarSherlock));
    } catch (Exception e) {
        Log.e(TAG, "Error enabling embedded tabs", e);
    }
}

//helper method
private void enableEmbeddedTabs(Object actionBar) {
    try {
        Method setHasEmbeddedTabsMethod = actionBar.getClass().getDeclaredMethod("setHasEmbeddedTabs", boolean.class);
        setHasEmbeddedTabsMethod.setAccessible(true);
        setHasEmbeddedTabsMethod.invoke(actionBar, true);
    } catch (Exception e) {
        Log.e(TAG, "Error marking actionbar embedded", e);
    }
}

这code完美的作品。在我的应用程序试了一下。 为进一步参考 - <一个href="https://groups.google.com/forum/#!topic/actionbarsherlock/hmmB1JqDeCk">https://groups.google.com/forum/#!topic/actionbarsherlock/hmmB1JqDeCk

this code works perfectly . Tried it in my app . for further reference - https://groups.google.com/forum/#!topic/actionbarsherlock/hmmB1JqDeCk

这篇关于重复动作条选项卡(S)与自定义视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆