如何创建机器人动作条与自定义视图和标签自定义、视图、机器人、动作

2023-09-04 07:24:09 作者:男人的咆哮ち

我要创建标签式动作条(NAVIGATION_MODE_TABS)与自定义视图(DISPLAY_SHOW_CUSTOM)。它不应该是这样的:

I want to create tabbed ActionBar (NAVIGATION_MODE_TABS) with custom view (DISPLAY_SHOW_CUSTOM). It should looks like this:

我只需要能够通过此次活动通过按钮的最上面一行导航 - 我会用动作条做正常的 - 无分页模式,还能够在第二排切换标签。如果我设置的ActionBar是在一个标签式模式,自定义视图中消失,似乎是选项卡式模式和自定义视图是相互排斥的......它甚至有可能吗?

I just need to be able to navigate through the activities via buttons in the top row - as I would do with ActionBar in normal - non tabbed mode, and also be able to switch tabs in second row. If I set ActionBar to be in a tabbed mode, the custom view disappears, it seems that tabbed mode and custom view are mutually exclusive... Is it even possible?

有更可能的方式该怎么办,没有动作条。通常我会创建带有按钮的布局,包括它在TabActivity(也就是现在的德precated),这一切。但我不觉得这会是最好的解决办法,所以任何帮助或建议是AP preciated。

There are more possible ways how to do that without ActionBar. Normally I would create a layout with buttons, include it in the TabActivity (which is now deprecated) and that's all. But I do not feel it would be the best solution, so any help or advice is appreciated.

在此先感谢。

编辑:经过一段时间的研究,我发现它的工作原理,它是不被显示我的4英寸的屏幕上。但是如我所料它仍然无法正常工作。在更宽的屏幕自定义视图显示在右侧的标签 - 这是确定的,但在4英寸的手机屏幕它不会显示在所有

After a little research I found that it works, it is just not gets displayed on my 4 inch screen. However it still does not work as I expected. On wider screens a custom view shows on the right side of the tabs - it is ok, but on the 4 inch phone screens it is not displayed at all.

我认为最好的解决办法是使用ActionBarSherlock库(我不喜欢使用pcated德$ P $的特点和我的应用程序也必须工作在pre - sdk11版本的设备)和片段 - 一个用于顶级动作条和第二个标签式视图。

I think the best solution is to use ActionBarSherlock library (I do not like using deprecated features and my app must work also on pre - sdk11 version devices) and fragments - one for top ActionBar and the second for tabbed view.

推荐答案

第一行中的按钮已经被添加为optionMenu项目:

The buttons in the top row have to be added as optionMenu items:

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    for (int i = 0; i < menuItems; i++)
    {
        if (i == 0)
        {
            menu.add(R.string.home).setIcon(R.drawable.button_home).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
            menu.getItem(0).setOnMenuItemClickListener(this);

        }
    }

    return super.onCreateOptionsMenu(menu);
}

在动作条的理念是略有不同的话,我应该会问的时候。从 Android开发者指南:

当你想提供导航选项卡中的活动,使用操作栏的标签是一个很好的选择(而不是使用TabWidget),因为系统适应操作栏中的标签不同的屏幕大小,将它们放置在主操作栏当屏幕足够宽,或在一个独立的酒吧(被称为堆积操作栏),当屏幕太窄。

When you want to provide navigation tabs in an activity, using the action bar's tabs is a great option (instead of using TabWidget), because the system adapts the action bar tabs for different screen sizes—placing them in the main action bar when the screen is sufficiently wide, or in a separate bar (known as the "stacked action bar") when the screen is too narrow.

 
精彩推荐
图片推荐