2017-07-29 5 views
-1

Après la mise en place d'un titre et d'un sous-titre pour ma barre d'outils, la mauvaise taille de police est utilisée. Que doit-on faire pour résoudre ce problème?Mauvaise taille de police pour le titre et le sous-titre de la barre d'outils

enter image description here

Java

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     Toolbar customToolbar = (Toolbar)findViewById(R.id.toolbarC); 
     customToolbar.setBackgroundColor(Color.parseColor("#E21836")); 

     TextView mTitle = (TextView) this.findViewById(R.id.toolbar_title); 
     mTitle.setText("Hello World"); 
     mTitle.setSingleLine(true); 

     TextView mSubtitle = (TextView) this.findViewById(R.id.toolbar_subtitle); 
     mSubtitle.setText("Hello World"); 
     mSubtitle.setSingleLine(true); 
    } 
} 

toolbarC.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbarC" 
    android:layout_width="match_parent" 
    android:layout_height="?actionBarSize" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

    <LinearLayout 
     android:id="@+id/header_text_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#00FFFFFF" 
     android:gravity="center_vertical" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/toolbar_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"/> 

     <TextView 
      android:id="@+id/toolbar_subtitle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      style="@style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle"/> 
    </LinearLayout> 
</android.support.v7.widget.Toolbar> 
+1

Je pense qu'il y a un problème dans votre barre d'outils id juste vérifier en xml –

Répondre

0

Vous avez trouvé le problème et l'avez résolu. Il y avait une copie cachée des vues de texte de la barre d'outils dans mon projet et le sous-titre & en double était ce qui m'a été montré lors du déploiement de mon application.

+0

Pourriez-vous expliquer quel était le problème? – cliff2310

-1

Augmenter la hauteur de barre d'outils pour ?actionBarSize

0

ajouter textSize à chaque textViews. Essayez comme ça

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar 
android:id="@+id/toolbar_2lines" 
android:layout_width="match_parent" 
android:layout_height="?actionBarSize" 
xmlns:android="http://schemas.android.com/apk/res/android"> 

<LinearLayout 
    android:id="@+id/header_text_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#00FFFFFF" 
    android:gravity="center_vertical" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/toolbar_title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="18sp" 
     style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"/> 

    <TextView 
     android:id="@+id/toolbar_subtitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="12sp" 
     style="@style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle"/> 
</LinearLayout> 

0

ajouter cette ligne, probablement qu'il utilise app_name comme titre getSupportActionBar() setDisplayShowTitleEnabled (false). et essayez d'utiliser dp au lieu de sp