我尝试在Collapsing Toolbar Layout
上添加此内容。
app:expandedTitleTextAppearance="@style/TextAppearance.AppCompat.Title"
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:
<style name="TextAppearance.AppCompat.Title">
<item name="android:textSize">32sp</item>
</style>
这就是我在Home.java中所拥有的并尝试删除它们但我仍然无法修复它。
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");
答案 0 :(得分:3)
通过将此添加到活动onCreate:
来修复它 CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout)
findViewById(R.id.collapsing_toolbar);
collapsingToolbar.setCollapsedTitleTextAppearance(R.style.CollapsedAppBar);
collapsingToolbar.setExpandedTitleTextAppearance(R.style.ExpandedAppBar);
并将其添加到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>
答案 1 :(得分:0)
您还可以将以下内容添加到app_bar_home.xml
中<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:collapsedTitleTextAppearance="@style/collapsed_app_bar"
app:contentScrim="@color/colorPrimary"
app:expandedTitleTextAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
然后注意 collapsedTitleTextAppearace 和 expandedTitleTextAppearance 属性。在我的例子中,我将以下内容添加到values资源文件下的style.xml中:
<style name="collapsed_app_bar" parent="@android:style/TextAppearance">
<item name="android:textSize">40sp</item>
<item name="android:textColor">#f0f</item>
</style>
希望这会有所帮助!!