How to completely replace the action bar of AppCompatActivity with custom action bar in Android?
<p>I am absolute beginner to Android. Now I am learning how to layout an Android app. So I started to use navigation drawer to together with toolbar. Now I am creating a custom action without default features. But it is not working.</p>

<p>This is my main activity layout</p>

<pre><code>&lt;android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"&gt;

    &lt;!-- This LinearLayout represents the contents of the screen  --&gt;

    &lt;LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"&gt;

        &lt;!-- The ActionBar displayed at the top --&gt;
        &lt;include
            layout="@layout/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" /&gt;

        &lt;!-- The main content view where fragments are loaded --&gt;
        &lt;FrameLayout
            android:id="@+id/flContent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" /&gt;
    &lt;/LinearLayout&gt;

    &lt;!-- The navigation drawer that comes from the left --&gt;
    &lt;!-- Note that `android:layout_gravity` needs to be set to 'start' --&gt;
    &lt;android.support.design.widget.NavigationView
        android:id="@+id/nvView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/white"
        app:menu="@menu/drawer_view" /&gt;
&lt;/android.support.v4.widget.DrawerLayout&gt;
</code></pre>

<p>This is my toolbar layout</p>

<pre><code>&lt;android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true"
    android:minHeight="?attr/actionBarSize"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:background="?attr/colorPrimaryDark"&gt;

&lt;/android.support.v7.widget.Toolbar&gt;
</code></pre>

<p>This is my activity class</p>

<pre><code>public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
</code></pre>

<p>This is style</p>

<pre><code>&lt;style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"&gt;
        &lt;!-- Customize your theme here. --&gt;
        &lt;item name="colorPrimary"&gt;@color/colorPrimary&lt;/item&gt;
        &lt;item name="colorPrimaryDark"&gt;@color/colorPrimaryDark&lt;/item&gt;
        &lt;item name="colorAccent"&gt;@color/colorAccent&lt;/item&gt;
    &lt;/style&gt;
    &lt;style name="AppTheme.NoActionBar"&gt;
        &lt;item name="windowActionBar"&gt;false&lt;/item&gt;
        &lt;item name="windowNoTitle"&gt;true&lt;/item&gt;
    &lt;/style&gt;
    &lt;style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /&gt;
    &lt;style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /&gt;
</code></pre>

<p>But when I start the activity, title and option to view menu items are included in the action bar even though I did not define in the layout like in screenshot.</p>

<p><a href="https://i.stack.imgur.com/BPhA1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BPhA1.png" alt="enter image description here"></a></p>

<p>So what I want to do is I want to completely replace the action bar with my custom toolbar and I want to erase the default behaviours.</p>

<p>So I tried to remove the title in this way in activity</p>

<pre><code>setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setTitle("");
        setSupportActionBar(toolbar);
</code></pre>

<p>But it is throwing error </p>

<p>This is the logcat</p>

<pre><code>01-23 12:28:45.945 2972-2972/? D/AndroidRuntime: Shutting down VM
01-23 12:28:45.945 2972-2972/? W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa614a908)
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime: FATAL EXCEPTION: main
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.waiyanhein.todo.todo/com.waiyanhein.todo.todo.MainActivity}: java.lang.NullPointerException
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:99)
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:137)
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5041)
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:511)
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:  Caused by: java.lang.NullPointerException
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at com.waiyanhein.todo.todo.MainActivity.onCreate(MainActivity.java:21)
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at android.app.Activity.performCreate(Activity.java:5104)
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at android.app.ActivityThread.access$600(ActivityThread.java:141) 
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:99) 
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:137) 
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5041) 
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method) 
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:511) 
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
01-23 12:28:45.945 2972-2972/? E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method) 
01-23 12:28:45.961 2972-2975/? D/dalvikvm: GC_CONCURRENT freed 249K, 13% free 2610K/2988K, paused 2ms+0ms, total 18ms
01-23 12:28:45.961 386-801/? W/ActivityManager:   Force finishing activity com.waiyanhein.todo.todo/.MainActivity
01-23 12:28:46.177 386-801/? D/dalvikvm: GC_FOR_ALLOC freed 1205K, 46% free 8703K/16012K, paused 15ms, total 15ms
01-23 12:28:46.209 386-402/? D/dalvikvm: GC_FOR_ALLOC freed 149K, 40% free 9732K/16012K, paused 19ms, total 19ms
01-23 12:28:46.241 386-402/? D/dalvikvm: GC_FOR_ALLOC freed 6K, 33% free 10832K/16012K, paused 15ms, total 15ms
01-23 12:28:46.241 386-402/? I/dalvikvm-heap: Grow heap (frag case) to 13.126MB for 2536932-byte allocation
01-23 12:28:46.301 386-401/? D/dalvikvm: GC_FOR_ALLOC freed 2K, 29% free 13307K/18492K, paused 59ms, total 59ms
01-23 12:28:46.309 386-389/? D/dalvikvm: GC_CONCURRENT freed &lt;1K, 29% free 13307K/18492K, paused 2ms+1ms, total 10ms
</code></pre>

<p>So my first question is why is that throwing error when I customize the action bar in activity? Is there anything wrong with my code? My second question is how to completely replace the action bar with my custom one as I asked above.</p>