Home » Android » android – how to programmatically show and hide action bar on one activity

android – how to programmatically show and hide action bar on one activity

Posted by: admin April 23, 2020 Leave a comment

Questions:

i got this one activity wherein i need to hide actionbar on the login interface then once login it will show the action bar.i got one activity only. if i put getActionBar on the main activity it gives me error.

heres the code:

How to&Answers:

For class extending Activity :

For class extending AppCompatActivity :

Answer:

Very simple.

Answer:

You can hide/Show the status bar on Android 4.1 (API level 16) and higher by using hide()/show() functionality

For more details you can visit here https://developer.android.com/training/system-ui/status.html

http://developer.android.com/guide/topics/ui/actionbar.html

Answer:

Change your Theme from the manifest file for the desire Activity…

Programmatically you can Invisible your Toolbar by this line of codes

if you extend your activity by Activity class then use below line of code to show or hide the Toolbar

and if you extend your activty from AppCompact Activity then use

For class extending Activity :

getActionBar().hide();
getActionBar().show();
For class extending AppCompatActivity :

Answer:

The ActionBar usually exists along Fragments so from the Activity you can hide it

and from the Fragment you can do it

Answer:

you can save it use sharedpreference like below

Answer:

This just worked for me: