For my actionBar, I want to create a layout as shown here: alt text

Here are 2 activations for which I want to make one menu.
Those. it should have a back button, a caption in the middle and a reload button

Actually here is an unfinished layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/custom_menu" android:layout_width="wrap_content" android:layout_height="wrap_content" android:color="#808080" android:orientation="horizontal" > <!-- текст по середине--> <TextView android:id="@+id/action_bar_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Type here:"> </TextView> <item android:id="@+id/reload_button" android:color="#ffffff" android:background="@drawable/custom_item" android:icon="@android:drawable/ic_menu_rotate"> </item> 

I have a few questions:
1) Do I still need to specify the "back" button here or can it be connected via code? If necessary, where to get the icon itself? Is it in drawable?
2) Am I doing everything right here? 3) It would be nice to see examples somewhere on the net, how people make their layout under actionBar
4) Is it possible to somehow move the actionBar title in the middle? Assign him the thickness?

  • look here . - KoVadim
  • I know about it, but not at all. I also need to keep the heading in the center and the frame for the "reload button" done - Stas0n
  • The picture "angle bracket - arrow" I found in the standard pictures in "@ drawable / abc_ic_ab_back_holo_light". - KoVadim
  • I don't have something like that .. - Stas0n
  • since you are doing a custom design - draw a button. All that business. - KoVadim

2 answers 2

For the back button you can set:

 getSupportActionBar().setDisplayHomeAsUpEnabled(true); 

For your "layout" labels use:

https://developer.android.com/reference/android/app/ActionBar.html#setCustomView (iint)

For your button in the menu description you need to specify:

 app:actionViewClass="resource.id" 
  • Already googled yesterday on this topic. So, some of the customization for some reason add their own style to activate: stackoverflow.com/questions/15518414/… Why? And then, is it possible to make a custom view for the bar without explicitly pointing the back button in it, and then register the actionBar.setDisplayHomeAsUpEnabled (true) ;? - Stas0n

Customization as in 1 picture:

 public boolean onCreateOptionsMenu(Menu menu) { ActionBar actionBar = getActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.setCustomView(R.layout.custom_menu); actionBar.setBackgroundDrawable(new ColorDrawable(Color.GRAY)); TextView textView = (TextView) findViewById(R.id.actionbar_title); textView.setText(R.string.app_name); getMenuInflater().inflate(R.menu.menu_master_view, menu); return super.onCreateOptionsMenu(menu); } 

custom_menu.xml :

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="vertical"> <TextView android:id="@+id/actionbar_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:textStyle="bold" android:textColor="#ffffff" android:textSize="18sp" /> </LinearLayout> 

menu_master_view.xml :

 <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/action_refresh" android:showAsAction="always" android:icon="@android:drawable/ic_menu_rotate" /> </menu>