I know that this is possible with xml files. but I want to do this using a style so that it is applicable for each of my windows, how to do this help.
You are still using xml for this. Just apply the style app broadly, not just one action. Please see the Android documentation for a full description:
https://developer.android.com/training/basics/actionbar/styling.html
Then apply your theme for the entire application or individual actions:
<application android:theme="@style/CustomActionBarTheme" ... />
EDIT: Here's how you have to handle the centering of the header:
In your action_bar.xml you will have something like this:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:text="SOME TITLE" android:textSize="18sp" /> </RelativeLayout>
Then in your onCreate () you will have something like:
getSupportActionBar().setCustomView(R.layout.action_bar);
If you need to have this in every action, you have 2 options:
- Brute force: put the above line of code in every onCreate action.
- Extend the action and put the ActionBar initialization code in onCreate. Then expand your own activity class for each action. Just remember to call super () in every onCreate () action.
SBerg413 08 Oct '13 at 9:59 on 2013-10-08 09:59
source share