样式
<style name="MainAppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
</style>
xml布局:
<androidx.drawerlayout.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolBar"
android:layout_width="match_parent"
android:layout_height="@dimen/tool_bar_height"/>
</LinearLayout>
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
活动中:
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.widget.Toolbar;
import androidx.drawerlayout.widget.DrawerLayout;
mToolbar = (Toolbar) findViewById(R.id.toolBar);
mToolbar.setNavigationIcon(R.drawable.ic_navigation_drawer);
actionBarDrawerToggle = new ActionBarDrawerToggle(
this,
mDrawerLayout,
mToolbar, R.string.application_name,
R.string.application_name) {
public void onDrawerClosed(View view) {
}
public void onDrawerOpened(View drawerView) {
}
};
mDrawerLayout.setDrawerListener(actionBarDrawerToggle);
但工具栏未显示在ActionBarDrawerToggle
中