I need to implement the following actionBar:
alt text

For this, I wanted to conduct such customization:

public boolean onCreateOptionsMenu(Menu menu) { ActionBar actionBar = getActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME); actionBar.setCustomView(R.layout.custom_menu); actionBar.setBackgroundDrawable(new ColorDrawable(Color.GRAY)); actionBar.setHomeButtonEnabled(true); actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); TextView textView = (TextView) findViewById(R.id.actionbar_title); textView.setText("title"); getMenuInflater().inflate(R.menu.menu_detail_view, menu); return super.onCreateOptionsMenu(menu); } 

Here is the 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" /> 

And menu_detail_view.xml - empty

The result is that the text is in the middle, but there is no "home" button. How to be? I do not even know what to rule ...

    1 answer 1

    Try setting the LinearLayout value to layout_width="wrap_content" . And then the entire layout takes all the visible space, and there is a button, but outside the screen.

    • oh shit it's brilliant !!!!) - Stas0n
    • and work with ActionBar transfer to onCreate - tim_taller
    • @monomi big difference? - Stas0n 4:21 pm
    • onCreateOptionsMenu designed to work with the menu and initialize the action bar there is no place - tim_taller
    • @monomi when working with fragments, it will be better to change ActionBar in onCreateOptionsMenu - Deadkenny