How To Center Icon in Android Action Bar

前端 未结 3 2096
故里飘歌
故里飘歌 2021-01-04 08:25

I\'m trying to center the icon in the android action bar. I\'m using a custom layout that has a button on the left side, an icon in the center and the menu options on the r

3条回答
  •  青春惊慌失措
    2021-01-04 08:54

    You can add a custom view to the action bar. Just add a LinearLayout as the custom view and add sub views to the linearlayout. I used this technique to add 4 buttons right in the middle.

    To add a custom view use actionBar.setCustomView(view). Also set the option DISPLAY_SHOW_CUSTOM using actionBar.setDisplayOptions.

    Once you have a custom view in the bar then use normal layout procedures to get the effect you want. One trick you could use would be to have 3 nested linear layouts and assign each a weight. For example 1,4,1 so the center layout gets the most space. Here is an example, of course you can leave out the buttons on the right side layout if you want it to be blank. With this approach you can achieve the exact center.

    
    
        
    
            

提交回复
热议问题