出于某种原因,我无法弄清楚为什么我的汉堡包图标无法被看到但仍然可以被选中,所有东西都被隔开,好像它仍然在那里。这也发生在我设置到登出部分的另一侧的3个水平点图标。
MainActivity.java
free_constructors
activity_main.xml中
public class MainActivity extends AppCompatActivity implements
NavigationView.OnNavigationItemSelectedListener {
private Toolbar mToolbar;
private DrawerLayout mDrawerLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar myToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(myToolbar);
// Find our drawer view
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
setupToolbarMenu();
setupNavigationDrawerMenu();
}
private void setupToolbarMenu() {
mToolbar = (Toolbar) findViewById(R.id.toolbar);
mToolbar.setTitle("Recovery Toolkit");
}
private void setupNavigationDrawerMenu() {
NavigationView navigationView = (NavigationView)
findViewById(R.id.nav_view);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
navigationView.setNavigationItemSelectedListener(this);
ActionBarDrawerToggle drawerToggle = new
ActionBarDrawerToggle(this,
mDrawerLayout,
mToolbar,
R.string.drawer_open,
R.string.drawer_close);
mDrawerLayout.addDrawerListener(drawerToggle);
drawerToggle.syncState();
}
toolbar.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activity.SplashActivity"
tools:openDrawer="start">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/MyMaterialTheme">
<include layout="@layout/toolbar" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
<!-- Navigation View -->
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="@dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header_main"
android:fitsSystemWindows="true"
app:menu="@menu/activity_main_drawer"
android:theme="@style/MyMaterialTheme"/>
nav_header_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"tools:context="com.granitemountainbhc.recoverytoolkit.activity.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/MyMaterialTheme">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:popupTheme="@style/MyMaterialTheme"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
答案 0 :(得分:0)
drawerToggle.setDrawerIndicatorEnabled(true);
添加此行。 示例:
.
.
mDrawerLayout.addDrawerListener(drawerToggle);
drawerToggle.setDrawerIndicatorEnabled(true);
drawerToggle.syncState();
(对不起。我没有足够的信用评论)
编辑: 你试试这个布局,看看它是否有效
<强> activity_main.xml中强>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activity.SplashActivity"
tools:openDrawer="start">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/MyMaterialTheme">
</android.support.design.widget.AppBarLayout>
<include layout="@layout/toolbar" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
<!-- Navigation View -->
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="@dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header_main"
android:fitsSystemWindows="true"
app:menu="@menu/activity_main_drawer"
android:theme="@style/MyMaterialTheme"/>
<强> toolbar.xml 强>
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"tools:context="com.granitemountainbhc.recoverytoolkit.activity.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/MyMaterialTheme">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:popupTheme="@style/MyMaterialTheme"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
答案 1 :(得分:0)
我感谢大家的帮助,但似乎我只是缺席了:
local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
一旦我补充说一切都开始正常工作了。再次感谢!