问题
I would like to center my app's title displayed on the ActionBar. So far I have customised its background color using only the style.xml file, like this:
<!-- Application theme. -->
<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">@drawable/action_bg</item>
<item name="android:layout_gravity">center</item>
</style>
But it wont center the title if I try to add:
<item name="android:layout_gravity">center</item>
I have found a hack where (here) we can make and load a separate "actionbar.xml" for more customisation options in the onCreate method and it works, but when the app starts it needs 1-2s to load this xml while the original actionbar is being displayed.
Is there really no other solution to costumize the actionbar (adding image logo, center text, etc.) within the style.xml? Do we need to do this programatically?
Thanks!!
来源:https://stackoverflow.com/questions/21131388/centring-the-title-on-the-android-anctionbar-using-the-style-xml-possible