how to programmatically show and hide action bar on one activity

前端 未结 7 804
闹比i
闹比i 2020-12-10 10:12

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

相关标签:
7条回答
  • 2020-12-10 10:44

    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();
    
    0 讨论(0)
  • 2020-12-10 10:52

    Very simple.

    getActionbar().hide();
    getActionbar().show();
    
    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-12-10 10:56

    This just worked for me:

    supportActionBar?.hide()
    
    0 讨论(0)
  • 2020-12-10 10:57

    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();
    
    }
    
    0 讨论(0)
  • 2020-12-10 11:03

    For class extending Activity :

    getActionBar().hide();
    getActionBar().show();
    

    For class extending AppCompatActivity :

    getSupportActionBar().hide();
    getSupportActionBar().show();
    
    0 讨论(0)
提交回复
热议问题