I'm trying to make an ActionBar that has:
- Home button as up enabled with title (to the left)
- TextView (centered)
- Overflow Menu items (to the right)
I was following this answer to an almost identical question. The difference is that I would like to show a title. I tried actionBar.setTitle("Title")
, but it gets cut off by the LinearLayout and isn't visible.
How can I create a custom View in the center of my ActionBar with the above elements?
Is it possible to do without overriding the entire ActionBar?
Edit:
I set up the ActionBar here:
final ActionBar actionBar = getSupportActionBar();
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setTitle("Title");
actionBar.setCustomView(R.layout.some_layout);
Here is the some_layout.xml
file:
<?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:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some Text" />
</LinearLayout>
Here is the resulting ActionBar I get from this (I set the LinearLayout background to green and text color to white):
Here is what I'm trying to get (without the green background):