有一个丑陋的方式做到这一点,你知道会的高度,通过使用自定义TextView
为ToolBar
里面的标题是什么,后来扩展一切,当用户旋转手机。
<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:textColor="?android:textColorPrimary"
android:id="@+id/titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</android.support.v7.widget.Toolbar>
在这里,你Activity
直接的onConfigurationChanged
,我们改变了ToolBar
的高度并设置了自定义标题的文本大小;
@Override
public void onConfigurationChanged(Configuration newConfig) {
View tb = findViewById(R.id.toolbar);
TextView titleTextVIew = (TextView) findViewById(R.id.titleTextView);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
tb.getLayoutParams().height = (int) Tool.convertDpToPixel(48, this);
titleTextVIew.setTextSize(TypedValue.COMPLEX_UNIT_SP,15);
}else {
tb.getLayoutParams().height = (int) Tool.convertDpToPixel(56, this);
titleTextVIew.setTextSize(TypedValue.COMPLEX_UNIT_SP,20);
}
super.onConfigurationChanged(newConfig);
}