2017-07-29 66 views
-1

爲我的工具欄實施標題和副標題後,出於某種原因使用了錯誤的字體大小。爲了解決這個問題需要做些什麼?錯誤的字體大小顯示爲工具欄標題和字幕

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

我認爲您的工具欄ID存在問題,只需在xml中籤入 –

回答

0

發現問題並解決了問題。我的項目中有一個隱藏的工具欄文本視圖副本,副本標題&是部署我的應用程序時顯示的內容。

+0

您能否解釋剛纔出現的問題? – cliff2310

-1

增加工具欄的高度,以?actionBarSize

0

爲每個textView添加textSize。試着這樣

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

加入這一行,也許它使用APP_NAME作爲標題 getSupportActionBar()setDisplayShowTitleEnabled(假)。 並嘗試使用dp代替sp

相關問題