本文介绍了如何在CollapsingToolbarLayout中增加标题的字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将其添加到我的Collapsing Toolbar Layout
上.
I tried to add this on my Collapsing Toolbar Layout
.
app:expandedTitleTextAppearance="@style/TextAppearance.AppCompat.Title"
app_bar_home.xml
app_bar_home.xml
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/CoordinatorLayout"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/AppBarLayout"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_height="300dp"
android:layout_width="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleGravity="center|center_horizontal"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleTextAppearance="@style/TextAppearance.AppCompat.Title">
<ImageView
app:backgroundTint="@color/text"
android:id="@+id/canteen_logo"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:scaleType="fitCenter"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7"
app:srcCompat="@drawable/canteen_logo1"
/>
<android.support.v7.widget.Toolbar
android:textAllCaps="true"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/toolbar_popup_style"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
这是我的Styles.xml:
And here's my Styles.xml:
<style name="TextAppearance.AppCompat.Title">
<item name="android:textSize">32sp</item>
</style>
这是我的Home.java文件中的内容,尝试删除它们,但仍然无法修复.
This is what I have in my Home.java and tried to remove them but I still couldn't get it fixed.
CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout)
findViewById(R.id.collapsing_toolbar);
final Typeface sp = Typeface.createFromAsset(this.getAssets(), "fonts/FuturaPTMedium.otf");
final Typeface tf = Typeface.createFromAsset(this.getAssets(), "fonts/FuturaPTBook.otf");
collapsingToolbar.setCollapsedTitleTypeface(sp);
collapsingToolbar.setExpandedTitleTypeface(tf);
setTitle("CANTEEN");
推荐答案
通过将其添加到活动onCreate中来解决此问题:
Fixed it by adding this to the activity onCreate:
CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout)
findViewById(R.id.collapsing_toolbar);
collapsingToolbar.setCollapsedTitleTextAppearance(R.style.CollapsedAppBar);
collapsingToolbar.setExpandedTitleTextAppearance(R.style.ExpandedAppBar);
并将其添加到styles.xml:
and adding this to styles.xml:
<style name="CollapsedAppBar" parent="@android:style/TextAppearance">
<item name="android:textSize">32sp</item>
</style>
<style name="ExpandedAppBar" parent="@android:style/TextAppearance">
<item name="android:textSize">76sp</item>
</style>
这篇关于如何在CollapsingToolbarLayout中增加标题的字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!