有没有办法在不扩展 TabActivity 或使用片段的情况下拥有包含独立内容的选项卡?
Is there a way to have tabs with independent content in them, without extending TabActivity or using fragments?
有没有办法在不扩展 TabActivity 或使用片段的情况下让选项卡中包含独立内容?
我是 android 开发的新手,我对 TabHost 和 TabView
很困惑
设计支持库有一个 TabLayout
您可以轻松使用。
The Design library’s TabLayout implements both fixed tabs, where the
view’s width is divided equally between all of the tabs, as well as
scrollable tabs, where the tabs are not a uniform size and can scroll
horizontally. Tabs can be added programmatically
However, if you are using a ViewPager for horizontal paging between
tabs, you can create tabs directly from your PagerAdapter’s
getPageTitle() and then connect the two together using
setupWithViewPager(). This ensures that tab selection events update
the ViewPager and page changes update the selected tab.
TabLayout tabLayout = ...;
tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
在 API 级别 21 中,actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS)
已被贬低为 TabLayout
。
更多,http://android-developers.blogspot.co.uk/2015/05/android-design-support-library.html
不使用片段?好吧,那是不可能的。您将不得不使用 ViewPager
,制作一些 Fragment
并制作一个将它们全部连接起来的片段适配器。
有没有办法在不扩展 TabActivity 或使用片段的情况下让选项卡中包含独立内容? 我是 android 开发的新手,我对 TabHost 和 TabView
很困惑设计支持库有一个 TabLayout
您可以轻松使用。
The Design library’s TabLayout implements both fixed tabs, where the view’s width is divided equally between all of the tabs, as well as scrollable tabs, where the tabs are not a uniform size and can scroll horizontally. Tabs can be added programmatically
However, if you are using a ViewPager for horizontal paging between tabs, you can create tabs directly from your PagerAdapter’s getPageTitle() and then connect the two together using setupWithViewPager(). This ensures that tab selection events update the ViewPager and page changes update the selected tab.
TabLayout tabLayout = ...;
tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
在 API 级别 21 中,actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS)
已被贬低为 TabLayout
。
更多,http://android-developers.blogspot.co.uk/2015/05/android-design-support-library.html
不使用片段?好吧,那是不可能的。您将不得不使用 ViewPager
,制作一些 Fragment
并制作一个将它们全部连接起来的片段适配器。