Android 自定义工具栏在我构建应用程序时不显示

Android 自定义工具栏在我构建应用程序时不显示,android,android-studio,android-toolbar,Android,Android Studio,Android Toolbar,我决定做我自己的工具栏 因此,我移除了常规工具栏: <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="false" android:theme="

我决定做我自己的工具栏

因此,我移除了常规工具栏:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="false"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar> //removetollbar
现在,当应用程序运行时,自定义工具栏不在那里


请根据我的经验提供帮助。要创建自定义工具栏,您的步骤是正确的。 但是我发现为CustomToolbar查找视图时出错

我试图解析你的代码

  • 为删除默认工具栏添加主题栏。[正确]
  • 创建布局自定义工具栏如:

  • 您确定它的布局正确吗?您是否已调试以确保
    \u CustomToolBar
    findViewById()
    行之后不为空?在您的主布局中是否可能有其他的
    视图
    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    
    </android.support.v7.widget.Toolbar>
    
    <include
        layout="@layout/customtoolbar"
        android:id="@+id/custombar" >
    
    </include>
    
    _CustomToolBar = (android.support.v7.widget.Toolbar) 
    findViewById(R.id.custombar);
    setSupportActionBar(_CustomToolBar);
    android.support.v7.widget.Toolbar _CustomToolBar;