gpt4 book ai didi

android - 如何在 CollapsingToolbarLayout 中增加标题的字体大小?

转载 作者:行者123 更新时间:2023-11-29 15:43:32 25 4
gpt4 key购买 nike

我试图在我的 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");

最佳答案

通过将此添加到 onCreate Activity 来修复它:

    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>

关于android - 如何在 CollapsingToolbarLayout 中增加标题的字体大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36560292/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com