I want to show a text in the right top corner of the actionbar. i have added the textview to the action bar using the following layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:background="#00000000" android:layout_gravity="right" android:gravity="right" android:layout_height="fill_parent"> <TextView android:id="@+id/balance_text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginRight="8dp" android:textAllCaps="true" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="#fff" android:layout_gravity="center_vertical|right" android:gravity="right" android:text="test balance" android:textStyle="bold" /> and in the activity as
LayoutInflater inflator = LayoutInflater.from(this); View v = inflator.inflate(R.layout.actionbar_layout, null); ((LinearLayout) v).setGravity(Gravity.RIGHT); actionBar.setCustomView(v); It works perfectly. But it adds text in the center of the action bar. I want the text to be placed in right. I tried with gravity as well. But nothing works.
Any suggestions.
mActionbar.setDisplayHomeAsUpEnabled(false);andmActionbar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);for yourActionbar.