Android工具栏图标缺失,但仍然可以选择



由于某种原因,我无法弄清楚为什么我的汉堡图标看不到,但仍然可以选择,一切都被隔开了,好像仍然存在。这也是我设置为注销部分的另一侧的3个水平点图标也会发生这种情况。

mainActivity.java

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();
}

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">
<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"/>

工具键.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>

nav_header_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/nav_drawer_width"
android:layout_height="190dp"
android:elevation="16dp"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@drawable/background_header">

<LinearLayout
    android:layout_width="@dimen/nav_drawer_width"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="15dp"
    android:paddingStart="15dp"
    android:paddingEnd="15dp"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="56dp">

    <ImageView
        android:id="@+id/user_profile"
        android:layout_width="@dimen/nav_drawer_profile_image_size"
        android:layout_height="50dp"
        android:gravity="bottom"
        app:srcCompat="@drawable/ic_account_circle_white_64dp"
        tools:ignore="ContentDescription" />
    <ImageView
        android:layout_width="@dimen/nav_drawer_width"
        android:layout_height="wrap_content"
        android:contentDescription="@string/item_desc" />

    <TextView
        android:id="@+id/txvName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="3"
        android:fontFamily="roboto-bold"
        android:gravity="bottom"
        android:text="@string/user_name"
        android:textColor="@color/colorPrimaryText"
        android:textSize="14sp" />
    <TextView
        android:id="@+id/txvEmail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:fontFamily="roboto"
        android:gravity="bottom"
        android:text="@string/email"
        android:textColor="@color/colorPrimaryText"
        android:textSize="14sp" />
</LinearLayout>

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"/>

工具键.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>

我感谢您的帮助,但似乎我只是缺少:

local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light"

我补充说,一切都开始正常工作。再次感谢!

相关内容

  • 没有找到相关文章

最新更新