簡體   English   中英

漢堡圖標不顯示?

[英]Hamburger icon not showing?

我剛開始使用Android Studio,正在創建一個漢堡包圖標,現在一切正常,但漢堡包圖標不可見,菜單按預期方式關閉和打開,可以單擊但該圖標不可見。任何幫助都會很大贊賞。

活動檔案

package com.example.greyhound;

import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;

public class MainActivity extends AppCompatActivity {
    private DrawerLayout draw ;
    ActionBarDrawerToggle toggle;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar tool = findViewById(R.id.toolbar);
        setSupportActionBar(tool);
        draw = findViewById(R.id.hamburger);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,draw,tool,R.string.open_menu,R.string.close_menu);
        draw.addDrawerListener(toggle);
        toggle.syncState();
    }

}

布局文件...

<?xml version="1.0" encoding="utf-8"?>
<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/hamburger"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

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

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

            <FrameLayout
                android:id="@+id/frame_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
            </FrameLayout>   
    </LinearLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:headerLayout="@layout/menu_layer"
        app:menu="@menu/burger_menu">
    </android.support.design.widget.NavigationView> 
</android.support.v4.widget.DrawerLayout>

菜單層

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:background="@color/colorAccent">

</LinearLayout>

和樣式表

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
</resources>

我嘗試添加/刪除布局文件,但問題仍然存在。 我認為樣式文件中存在問題,因此我將“ windowActionBar”設置為true,我也在這里查找。

打電話之前

 toggle.syncState();

加:

  actionBar.setDisplayHomeAsUpEnabled(true); // this sets the button to the back icon actionBar.setHomeButtonEnabled(true); // makes it clickable actionBar.setHomeAsUpIndicator(R.drawable.ic_drawer);// set your own icon 

希望這會幫助你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM