Call
if (getSupportActionBar() != null)
getSupportActionBar().hide();
or just:
getActionBar()
in android.support.v7.app.ActionBarActivity I get such exception:
...
java.lang.NullPointerException
at android.support.v7.app.ActionBarImplICS.hide(ActionBarImplICS.java:302)
at android.support.v7.app.ActionBarImplJB.hide(ActionBarImplJB.java:20)
...
EDIT: it just happens when activity have Theme:
<style name="MyTheme" parent="Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">false</item>
</style>
note:
getSupportActionBar()
do not return null
If you want to hide Action Bar from the entire application (from all Activities and fragments), then you can use this method. Just go to res -> values -> styles. xml and change the base application to “Theme. AppCompat.
So basically we just need to change DarkActionBar to NoActionBar. NoActionBar theme prevents the app from using the native ActionBar class to provide the app bar. Thus it removes the title of every activity.
ActionBar actionBar = getActionBar(); actionBar. hide();
meet the same problem ,but I use code to set fullscreen and noActionbar below instead of theme in xml:
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getSupportActionBar().hide();
setContentView(R.layout.page_welcome);
initViews();
}
this code runs well before ICS but crashs caused by NullPointException above ICS,After some experiments,I got the solution:delete one line code which set no title as below:
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getSupportActionBar().hide();
setContentView(R.layout.page_welcome);
initViews();
}
Then it works well at all platforms. : )
As I understand
if (getSupportActionBar() != null)
getSupportActionBar().hide();
is no correct!
Becouse getSupportActionBar()
return not-null instance of
(android.support.v7.app.ActionBarImplICS)
after that we can call hide function (getSupportActionBar().hide();
)
but inside this function we will have NullPointerException because variable mActionBar
inside
android.support.v7.app.ActionBarImplICS instance == null
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/android/support/v7/app/ActionBarImplICS.java#302
As I understand inside constructor of android.support.v7.app.ActionBarImplICS
mActionBar = activity.getActionBar();
return null, because our Activity does not have ActionBar via Theme
<style name="MyTheme" parent="Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">false</item>
</style>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With