【问题标题】:Creating Swipe Views with tabs in Android 5.0在 Android 5.0 中创建带有标签的滑动视图
【发布时间】:2014-12-16 20:45:54
【问题描述】:

在 Android 5.0 之前制作如下滑动选项卡式布局:

只需要以下代码:

@Override
public void onCreate(Bundle savedInstanceState) {
    final ActionBar actionBar = getActionBar();
    ...

    // Specify that tabs should be displayed in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create a tab listener that is called when the user changes tabs.
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {
        public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
            // show the given tab
        }

        public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
            // hide the given tab
        }

        public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
            // probably ignore this event
        }
    };

    // Add 3 tabs, specifying the tab's text and TabListener
    for (int i = 0; i < 3; i++) {
        actionBar.addTab(
                actionBar.newTab()
                        .setText("Tab " + (i + 1))
                        .setTabListener(tabListener));
    }
}

但鉴于 ActionBar 上的导航方法已被弃用,我如何实现这种类型的视图以与 Android 5.0 及之前版本兼容?

【问题讨论】:

标签: android android-5.0-lollipop android-tabs


【解决方案1】:

【讨论】:

  • 升级到工具栏并不能解决这些方法已被弃用的事实
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多