2016-03-06 79 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