0

i am customizing my Action bar using styles. I am using custom style and setting it to the application tag in manifest.

<style name="AppBaseTheme" parent="@style/Theme.AppCompat">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
    <item name="android:titleTextStyle">@style/action_bar_title_text</item>
    <item name="android:background">@drawable/cross_pattern</item>
</style>

<style name="action_bar_title_text">
    <item name="android:textColor">@color/action_bar_title_text_color</item>
    <item name="android:textSize">@dimen/action_bar_title_text_size</item>
    <item name="android:gravity">center</item>
</style>

I am setting the title in the action bar also. Is there any way to center align the text ?

The issue is that i know how to do it via custom views, but i have to do it by styles.

I really don't understand the reason for downvoting. I thought that if you can change background style of action bar using custom style's so i thought that maybe you can align the text in Action bar to center. I have tried it myself first, but i was unsuccessful so i asked it here then i asked question here. I think it is a good question.

Instead of answers , my question is only getting downvoted.

Rahul Gupta
  • 5,275
  • 8
  • 35
  • 66
  • Not possible out of the box AND this is an anti pattern. I think you have to create a custom action bar view or text view inside the actionbar – DarkLeafyGreen Dec 26 '13 at 10:36
  • http://stackoverflow.com/questions/18418635/how-to-align-title-at-center-of-actionbar-in-default-themetheme-holo-light – rajahsekar Dec 26 '13 at 10:40
  • Did you try by putting android:layout_width="match_parent" to your action_bar_title_text style? – Kameswari Dec 26 '13 at 10:41
  • please kindly post the reason for downvoting – Rahul Gupta Dec 26 '13 at 11:56
  • I really don't understand the reason for downvoting. I thought taht you can change background style of action bas using custom style so i thought that maybe you can align the text in Action bar to center. I have tried myself first, then i asked question here. I think it is a good question – Rahul Gupta Dec 27 '13 at 16:45

2 Answers2

0

You can download this app from Google Play. It is a Hacker News app. Also, you can find what you're looking for in this repository.

Hope it helps! :D

Jorge E. Hernández
  • 2,800
  • 1
  • 26
  • 50
-5

I think it's

android:layout_gravity="center"

Try it and tell me if it's okay

Nemka
  • 100
  • 11