2017-07-24 3 views
1

J'ai une barre d'outils avec un TextView à l'intérieur avec match_parent pour centrer le texte mais chaque fois que je le fais, il devient plus grand que l'écran et cache le texte.Barre d'outils Android TextView match_parent devient plus grand que l'écran

Ici vous avez une capture de celui-ci en cours d'exécution

enter image description here

Comment cela ressemble dans l'aperçu

enter image description here

Et enfin comment je mettre en œuvre:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    android:orientation="vertical"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     tools:layout_editor_absoluteY="0dp" 
     tools:layout_editor_absoluteX="8dp"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:theme="@style/ToolBarStyle" > 

      <TextView 
       android:id="@+id/toolbar_title" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:gravity="center" 
       android:text="@string/title_activity_anuncios" /> 

     </android.support.v7.widget.Toolbar> 

    </android.support.design.widget.AppBarLayout> 

    <android.support.constraint.ConstraintLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

    </android.support.constraint.ConstraintLayout> 

</LinearLayout> 

Répondre

1

vérifier votre thème sur le style ou un ensemble thème d'activité du

manifeste
android:theme="@android:style/Theme.Translucent.NoTitleBar" 

Si le thème de l'activité est correcte, vous pouvez vérifier votre activité >> méthode onCreate .

ActionBar actionBar = getSupportActionBar(); 
    if (actionBar != null) { 
     actionBar.setTitle("Your Title"); 
    } 
+0

Merci, j'ai complètement oublié ça – MrDick

0

Mettez dans votre barre d'outils

app:contentInsetStart="0dp"