Android - 中心标题先于其他任何内容

时间:2012-04-27 12:17:08

标签: android center title

又来了! 我想将我的应用程序的标题集中在Android中。我知道我可以使用自定义布局,或/和以编程方式(((TextView)((FrameLayout)((LinearLayout)((ViewGroup) getWindow().getDecorView()).getChildAt(0)).getChildAt(0)).getChildAt(0)).setGravity(Gravity.CENTER);

无论如何,无论我使用何种方式执行此操作,标题都会在窗口加载后以小延迟为中心,这是我不喜欢的。所以,我的问题是:是否有一种方法可以将标题栏的文本居中。我不想打开应用程序,看左边的文本,然后几秒后,看看它是如何集中在高级栏上。 我还使用一个自定义主题来指定标题的样式,所以。在样式文件中我尝试了<item name="android:gravity">center</item>,但它不起作用。

<resources>
<style name="Theme.NoBackground" parent="android:Theme">
    <item name="android:windowTitleBackgroundStyle">
        @style/WindowTitleBackground
    </item>
</style>
</resources>

<?xml version="1.0" encoding="utf-8"?>
<resources> 
<style name="WindowTitleBackground">
   <item name="android:padding">2dp</item>
   <item name="android:gravity">center</item>
</style>
</resources>

感谢您的回答。

0 个答案:

没有答案