2016-04-24 146 views
1

我改变THA状态栏的颜色从styles.xml:如何设置标题在Android状态栏中中心

<resources> 

<string name="app_name">Qu-easy</string> 
<item name="colorPrimaryDark">@color/custom_theme_color</item> 
</resources> 

<resources> 

<color name="custom_theme_color">#42A5F5</color> 
<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!-- Customize your theme here. --> 

    <item name="colorPrimaryDark">@color/custom_theme_color</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

我也是从string.xml更改状态栏标题

如何将标题设置为状态栏的中心? 我想像gravity.center?

+0

Make custome关于这个的行动酒吧,而不是塞纳标题引用这个接受的答案http://stackoverflow.com/questions/18418635/how-to-align-title-at-center-of-actionbar-in-default-themetheme-holo-光 –

回答

0

试试这个: -
这里,您需要在onCreate方法

getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
getSupportActionBar().setCustomView(R.layout.custom_actionbar); 
ActionBar.LayoutParams p = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 
p.gravity = Gravity.CENTER; 

custom_actionbar.xml布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="50dp" 
android:orientation="vertical" 
android:gravity="center" 
android:layout_gravity="center"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:text="XYZ" 
    android:textColor="#ffffff" 
    android:id="@+id/mytext" 
    android:textSize="30dp" 
    android:textStyle="bold"/> 

</LinearLayout> 

添加一个XML文件
写下面的代码这绝对会为你工作

+0

我不使用一个操作栏,只是一个状态栏 –

+0

根据我的知识状态栏只是操作栏。两者具有相同的功能。 ,在这里您还可以通过编辑主题来制作中心文字。 ,你可以把ActionBarActivity作为你的操作栏 –