BaseActivity 在每个 activity 中实现 Navigation Drawer 和 Toolbar
BaseActivity to implement Navigation Drawer and Toolbar in every activity
我创建了一个基础 activity 和基础布局来扩展它们,以便在我的所有活动中获得相同的导航抽屉和工具栏。但是,我想在我的 activity 之一中添加滑动选项卡布局。我应该为此创建一个新布局吗?或者有什么方法可以将此滑动选项卡布局动态添加到我的扩展基础 activity?
activity_base.xml
<include android:id="@+id/app_bar" layout="@layout/app_bar"></include>
<android.support.v4.widget.DrawerLayout
android:layout_below="@+id/app_bar"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Listview to display slider menu -->
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="@color/itembackground"
android:choiceMode="singleChoice"
android:divider="@color/list_divider"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector" />
</android.support.v4.widget.DrawerLayout>
您可以在 Fragment
中实现滑动标签,而您正在 FrameLayout
中加载。可以使用 ViewPager
和 ActionBar.TabListener
界面实现滑动选项卡。 ViewPager
可以将选项卡 Fragment
保存在 FragmentStateAdapter
中并使用 getChildFragmentManager()
访问它们。这样,无需为选项卡式屏幕创建单独的布局,只需从 BaseActivity
扩展并使用带有选项卡的 Fragment
。
有关详细信息,请参阅 Creating Swipe Views with Tabs 示例。
我创建了一个基础 activity 和基础布局来扩展它们,以便在我的所有活动中获得相同的导航抽屉和工具栏。但是,我想在我的 activity 之一中添加滑动选项卡布局。我应该为此创建一个新布局吗?或者有什么方法可以将此滑动选项卡布局动态添加到我的扩展基础 activity?
activity_base.xml
<include android:id="@+id/app_bar" layout="@layout/app_bar"></include>
<android.support.v4.widget.DrawerLayout
android:layout_below="@+id/app_bar"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Listview to display slider menu -->
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="@color/itembackground"
android:choiceMode="singleChoice"
android:divider="@color/list_divider"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector" />
</android.support.v4.widget.DrawerLayout>
您可以在 Fragment
中实现滑动标签,而您正在 FrameLayout
中加载。可以使用 ViewPager
和 ActionBar.TabListener
界面实现滑动选项卡。 ViewPager
可以将选项卡 Fragment
保存在 FragmentStateAdapter
中并使用 getChildFragmentManager()
访问它们。这样,无需为选项卡式屏幕创建单独的布局,只需从 BaseActivity
扩展并使用带有选项卡的 Fragment
。
有关详细信息,请参阅 Creating Swipe Views with Tabs 示例。