缺少汉堡图标Android

时间:2017-01-05 06:49:30

标签: java android hamburger-menu

我尝试搜索有关汉堡图标的不同答案,但没有找到类似的东西。我正在尝试创建一个汉堡包图标,并一直在关注教程。代码运行正常,但是当我在虚拟设备中打开它时,图标丢失了。任何建议都表示赞赏。

activity_main xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.android.navigationapp.navigationapp.MainActivity"
android:id="@+id/drawerLayout">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:text="Main Layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView"
        android:layout_gravity="center_vertical"
        android:textAlignment="center"
        android:textSize="24dp" />
</LinearLayout>

<android.support.design.widget.NavigationView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    app:menu="@menu/navigation_menu"
    android:layout_gravity="start">
</android.support.design.widget.NavigationView>

</android.support.v4.widget.DrawerLayout>

MainActivity Java

package com.android.navigationapp.navigationapp;

import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {

private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mToggle;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
    mToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.open, R.string.close);

    mDrawerLayout.addDrawerListener(mToggle);
    mToggle.syncState();

    getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    if (mToggle.onOptionsItemSelected(item)) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}
}

0 个答案:

没有答案