android - How to set menu items to the left side of actionbar? -


I am creating an Android application that contains an actionben and the actionbars are menu items of both sides, The menu item must be left on the left side and a menu item to the right of the actionbar.

For this, I have created a custom layout and set it in the action bar. As shown in the image below

Custom layout action bar

But I just want to place the menu items on the left side and the second screenshot shows the action bar with the menu item

 Action with menu item

This includes menu items in the taskbar. So, I want the plus button to put the menu item on the left as the screen shot on the left, but I do not want to use custom layout for it,

Also, I should sort the font style. And put it in the center.

Please help me I spent many hours on this.

Thanks

You must create a custom view for that For the options menu inflation can not be used.

The theme of the style of activity. Set to AppCompat and do not use the noctionbar in the activity or app style.

Create a custom_manu layout

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" & gt; & Lt; Android background = Android layout_width = Android layout_height = Android: scaleType = "centerInside" Android: "Adr / actionBarSize": "Attr / actionBarSize": "Attr / actionBarSize": "attr / actionBarSize" @ + ID / Action_Aid "Android: Layout_Alternative Converter =" True "Android: Layout_AlgunatureTest =" True "/> & Lt; Android: layout_width = "wrap_content" Android: scaleType = "centerInside" Android: ID = "@ + id /": "Text / Video": "Attr / actionBarItemBackground": Text = "Newsfeed" Android background = Android: layout_height = "Attr / actionBarSize" Android: textSize = "30sp" Android: Text-style = "bold" Android: layout_marginLeft = "5dp" Android: textcolor = "#FFF" Android: paddingTop = "5dp" Android: layout_toRightOf = "@ + id / Action_add "Android: layout_alignParentTop =" true "/> & Lt; Android: "layout / wp" android layout_width = Android layout_height = Android: scaleType = "centerInside" Android: "ADR =" / "-" @ + ID / Action_search "Android: Layout_specialpaintright =" True "Android: Layout_LinePicturetop =" True "/> & Lt; / RelativeLayout & gt;   

Add the following code to your activity on the Create

  @Override Secure Zero Create (Bundle Saved InstantState) {super.onCreate (savedInstanceState); SetContentView (R.layout.activity_mainfeed); Actionbore mActionBar = getSupportActionBar (); MActionBar.setDisplayShowHomeEnabled (incorrect); MActionBar.setDisplayShowTitleEnabled (incorrect); LayoutInfoLe = Layout Inflator From (this); View customview = li.inflate (R.layout.custom_menu, null); MActionBar.setCustomView (customView); MActionBar.setDisplayShowCustomEnabled (true); ImageButton addContent = (image button) customView.findViewById (R.id.action_add); AddContent.setOnClickListener (New View.OnClickListener () {@Override Click Public Zero (see View) {// ...}}); ImageButton Search = (ImageButton) customView.findViewById (R.id.action_search); Search.setOnClickListener (New View.OnClickListener () {@Override Click Public Zero (see View) {// ...}}); }    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -