2017-07-29 2 views
-1

Nach dem Implementieren eines Titels und Untertitels für meine Symbolleiste wird aus irgendeinem Grund die falsche Schriftgröße verwendet. Was muss getan werden, um dies zu beheben?Falsche Schriftgröße für Symbolleistentitel und -untertitel

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

Ich denke, es gibt ein Problem in Ihrer Toolbar ID nur überkreuzen xml –

Antwort

0

Das Problem gefunden und es gelöst haben. Es gab ein verstecktes Duplikat der Symbolleisten-Textansichten in meinem Projekt und der doppelte Titel & Untertitel war das, was mir bei der Bereitstellung meiner App angezeigt wurde.

+0

Könnten Sie erklären, was war das Problem? – cliff2310

-1

Zunahme Toolbar Höhe zu ?actionBarSize

0

fügen Sie textSize zu jedem textViews hinzu. Versuchen Sie, wie dieser

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

diese Zeile hinzufügen, wahrscheinlich ist es mit app_name als Titel getSupportActionBar() setDisplayShowTitleEnabled (false). und versuchen mit dp anstelle von sp

Verwandte Themen