3

I need to hide or change color my activity action bar. But when I try to do this I got an error FATAL EXCEPTION: main.

My activity theme is android:theme="@style/Theme.AppCompat.Light.Dialog

To hide

getSupportActionBar().hide();

To change background color

android.app.ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.RED));

I am stuck with this error.

Error log

10-03 18:09:38.088 14160-14160/com.example.myown.myapplication 
E/AndroidRuntime: FATAL EXCEPTION: main

Process: com.example.myown.myapplication, PID: 14160

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myown.myapplication/com.example.myown.myapplication.MainActivity}: java.lang.NullPointerException
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
JBR
  • 136
  • 9

1 Answers1

5

Dialog theme do not have any ActionBar, use Theme.AppCompat.Light.

If you still want to use the Dialog theme and want to hide the title bar, call supportRequestWindowFeature(Window.FEATURE_NO_TITLE); immediately after super.onCreate.

Nabin Bhandari
  • 15,949
  • 6
  • 45
  • 59