【问题标题】:How to get current tab position correctly for bottombar in android?如何在android中正确获取bottombar的当前标签位置?
【发布时间】:2016-08-27 19:11:12
【问题描述】:

我使用 setDefaultTabPosition(和/或 selectTabAtPosition)将标签位置设置为 2,我得到了 标签 2标题/图标(字符串/图像)从屏幕突出显示,这是预期的。

内容(片段)仍以tab 0的显示。

我发现这是因为 getCurrentTabPosition() 没有返回正确的标签位置。请参见下面的代码。期望看到 2,但得到了 0。

我做了一个实验,将 getCurrentTabPosition() 放在监听器中,它似乎工作正常。 (但在任何点击选项卡之前始终为 0)

这是一个错误,还是我错过了什么?

以下代码的Log.e结果:E/currTabPosition: 0

    int temp=2;

    // I tried both, any one of them
    bottomBar.setDefaultTabPosition(currBb); 
    bottomBar.selectTabAtPosition(temp);

    temp = bottomBar.getCurrentTabPosition();

    Log.e("currTabPosition", ""+temp);

下面的linke是bottombar项目:

https://github.com/roughike/BottomBar

【问题讨论】:

  • 还有一个错误?如果我在位置 2 设置默认选项卡,那么即使我单击 0 和/或 1,它也始终在屏幕上处于活动状态,直到单击 2。

标签: android uinavigationbar


【解决方案1】:
  • 默认位置
bottomBar.setDefaultTabPosition(0);
  • 设置监听器
bottomBar.setOnTabSelectListener(new OnTabSelectListener() { @覆盖 公共无效 onTabSelected(@IdRes int tabId){ 如果(tabId == R.id.tab_favorites){ } } });

【讨论】:

    猜你喜欢
    • 2017-04-18
    • 1970-01-01
    • 1970-01-01
    • 2017-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多