Centring the title on the android AnctionBar using the style.xml possible?

被刻印的时光 ゝ 提交于 2019-12-24 00:14:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!