2016-04-24 15 views
1

änderte ich tha Farbe der Statusleiste von styles.xml:Wie der Titel in der Mitte in Android Statusleiste setzen

<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> 

ich auch die Titel von string.xml der Statusleiste ändern:

<resources> 

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

Wie kann ich den Titel in die Mitte der Statusleiste setzen? Ich denke sowas wie gravity.center?

+0

Machen custome Action bar über diese und dann cener der Titel verweisen diese akzeptierte Antwort http://stackoverflow.com/questions/18418635/how-to-align-title-at-center-of-actionbar-in-default-themetheme-holo- Licht –

Antwort

0

versuchen Sie dieses: -
Hier können Sie eine XML-Datei
Schreib folgenden Code in onCreate Methode

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 Layout-

<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> 

Dieser hinzufügen müssen wird auf jeden Fall Arbeit für Sie

+0

Ich benutze keine Aktionsleiste, nur eine Statusleiste –

+0

nach meinem Wissen Statusleiste ist nichts anderes als die Aktionsleiste. beide haben die gleiche Funktionalität. und hier können Sie auch Text zentrieren, indem Sie Ihr Thema bearbeiten. und Sie können 'ActionBarActivity' für Ihre Aktionsleiste verwenden –

Verwandte Themen