Add button in android action bar

后端 未结 2 497
余生分开走
余生分开走 2021-01-15 03:59

I trying to add a button beside HealthyApp, but no luck .

This is my initial code and image

  final ActionBar actionBar = getSupportActionBar();
             


        
2条回答
  •  温柔的废话
    2021-01-15 04:47

    In your Activity layout

    
            
            

    In your Activity

    public class YourActivity extends ActionBarActivity {
    
        private Toolbar toolbar;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.your_acticity_layout);
    
            // Set a Toolbar to replace the ActionBar.
            toolbar = (Toolbar) findViewById(R.id.toolbar);
            toolbar.setTitle("");
            setSupportActionBar(toolbar);
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    
           }
    
           // ... your other methods
    }
    

    In your Manifest, Activity tag

    
    

    In your style.xml

    
    

    If you need a better code sample: Just download https://github.com/chrisbanes/cheesesquare , It has the example toolbar.

提交回复
热议问题