2016-03-06 77 views
1

我的意圖是使用自定義視圖(TextView + ImageView)並將其作爲視圖放入工具欄中。如何獲取工具欄的默認TextView樣式的標題?我想讓我的TextView在我的自定義視圖具有完全相同的outfit.I試過造型也喜歡:Android工具欄標題樣式

setTypeface(Typeface.DEFAULT_BOLD); 
setTextSize(18); 
setTextColor(Color.BLACK); 

但它仍然看起來不同,這些描述的地方,因爲我實在找不到them.Or我可以再利用標題的風格?當涉及到代碼特別是樣式時,我感到有點困惑。

在此先感謝。

回答

0

在你的座標佈局中,放置這個。

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" > 
     <TextView 
      android:id="@+id/title" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="20dp" 
      android:text="Ezy Ride" 
      android:textColor="#ffffff" /> 
    </android.support.v7.widget.Toolbar> 

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

現在您的應用欄佈局已準備就緒。根據需要自定義它。

在Java

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
    TextView toolbarTitle = (TextView)toolbar.findViewById(R.id.title); 
    //here set all you want!! 
+0

謝謝,但,這是一個標準的辦法,我知道我現在的情況。在它必須做程式設計和BOLD + 18 SP看起來很像標題,但仍然不同。 – Dokuzov

+1

有關材料標準,請參閱https://www.google.com/design/spec/layout/structure.html#structure-app-bar – Sibidharan