2013-03-10 83 views

回答

14

只是hide()

getActionBar().hide(); 
当你想隐藏它,并使用 show()

getActionBar().show() 

当你想证明这一点。就是这样。

请记住,如果您使用的是View.SYSTEM_UI_FLAG_FULLSCREEN,则无法正常工作。

+0

感谢如何ü可以将其隐藏,当你按下任何地方屏幕上? – ymerdrengene 2013-03-10 20:40:45

+0

@ymerdrengene覆盖onTouch() – 2013-03-10 20:41:08

+0

@RaghavSood调用show()/ hide()被调用时存在延迟。这可以避免吗? – Ammar 2014-04-15 06:51:43

1

试试这个。你在这里调用隐藏或显示方法,并根据您的建议

public class AbstractActivity Activity { 

    private boolean showActions = false; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     ActionBar bar = getSupportActionBar(); 
     if (bar != null) { 
     bar.setHomeButtonEnabled(true); 
     bar.setDisplayShowHomeEnabled(true); 
     } 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     return super.onCreateOptionsMenu(menu); 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     int id = item.getItemId(); 
     switch (id) { 
     case android.R.id.home: 

     return true; 
     default: 
     // Nothing to do here 
     return super.onOptionsItemSelected(item); 
     } 
    } 

    private void handleActionBarTitle(boolean show) { 
     ActionBar actionBar = getSupportActionBar(); 
     if (actionBar == null) { 
     return; 
     } 
     actionBar.setDisplayShowTitleEnabled(show); 
    } 


    protected void disableActions() { 
     this.showActions = false; 
    } 

    protected void enableActions() { 
     this.showActions = true; 
    } 

    protected void hideActionBarTitle() { 
     handleActionBarTitle(false); 
    } 

    protected boolean showActions() { 
     return showActions; 
    } 

    protected void showActionTitle() { 
     handleActionBarTitle(true); 
    } 

您的活动可能只需要扩展了这个AbstractActivity你的答案:)但是

+0

我想我的问题还不清楚。如果你可以去“fullscrean-mode”,而不是显示/隐藏操作栏,我会发现如何去做。 – ymerdrengene 2013-04-03 17:53:45