Add button in android action bar

后端 未结 2 479
余生分开走
余生分开走 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:46

    Add toolbar inside your xml . and use NoActionBar in your activity theme .

    add these toolbar in your xml on top

    
    
        
    
            

    add these theme in your activity in Menifest.xml

    android:theme="@style/Theme.AppCompat.Light.NoActionBar"

    and add these code in your activity ....

    Toolbar topToolBar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(topToolBar);
    ActionBar actionBar = getSupportActionBar();;
    actionBar.setDisplayHomeAsUpEnabled(true);
    

    Output:-

    OR

    I think it is possible with the icon only .....

    use this item in menu.xml

    
    
        
    
    

    Note:- use android:icon="@drawable/YourImageWithTextDelete" put here your image .....

提交回复
热议问题