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
Change your Theme from the manifest file for the desire Activity...
Theme.AppCompat.NoActionBar
or
Theme.AppCompat.Light.NoActionBar
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
getActionBar().hide();
getActionBar().show();
and if you extend your activty from AppCompact Activity then use
For class extending Activity :
getActionBar().hide(); getActionBar().show(); For class extending AppCompatActivity :
getSupportActionBar().hide();
getSupportActionBar().show();
Very simple.
getActionbar().hide();
getActionbar().show();
You can hide/Show
the status bar on Android 4.1 (API level 16) and higher by using hide()/show()
functionality
// Hide the status bar.
ActionBar actionBar = getActionBar();
actionBar.hide();
// Show the status bar.
actionBar.show();
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
This just worked for me:
supportActionBar?.hide()
you can save it use sharedpreference like below
public class MainActivity extends Activity
{
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
loadActionbar();
btn=(Button)findViewById(R.id.mainButton1);
btn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View p1)
{
if(getActionBar().isShowing()==true){
getActionBar().hide();
saveActionBar();
}
else{
getActionBar().show();
saveActionBar();
}
}
})
public void saveActionBar(){
SharedPreferences pref=PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor=pref.edit();
editor.putBoolean("save",getActionBar().isShowing());
editor.apply();
}
public void loadActionbar(){
SharedPreferences pref=PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
boolean i=pref.getBoolean("save",getActionBar().isShowing());
if(i!=true){
getActionBar().hide();
}
else
getActionBar().show();
}
For class extending Activity :
getActionBar().hide();
getActionBar().show();
For class extending AppCompatActivity :
getSupportActionBar().hide();
getSupportActionBar().show();