To put a right-aligned spinner on action bar, I have to use a custom view with relative layout. But after I put custom view on the action bar, I find that app title disappear, it must be impacted by putting custom view on action bar.
Is it possible to display both title and custom view on action bar? Otherwise I have to put title in customer view as well, but I don't want do go that way.
The custom view will replace the Title bar. I suggest you to include a textview for the app title in your custom view so that you have more ground to play.
Actually it doesn't "replace". This can be shown by the hierarchy viewer. it's just that if you set your custom view too big, it will be ON TOP OF the title. however, if you only put something like a spinner, you can set it to be right aligned and the title will be shown.
Here's XML I used to put an image view on the right:
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="68dp"
android:layout_height="31dp"
android:padding="4dp"
android:layout_gravity="center_vertical|right"
android:layout_marginRight="4dp"
android:onClick="onImageClicked"
android:background="@drawable/mypic_bg"
android:src="@drawable/logo_mypic" />
and in code:
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM
| ActionBar.DISPLAY_HOME_AS_UP
| ActionBar.DISPLAY_SHOW_HOME
| ActionBar.DISPLAY_SHOW_TITLE);
actionBar.setCustomView(R.layout.my_title_bar);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With