gpt4 book ai didi

android - 工具栏副标题不出现

转载 作者:IT王子 更新时间:2023-10-28 23:33:06 27 4
gpt4 key购买 nike

我在一个 collapsingtoolbarlayout 中设置了我的工具栏,如下所示:

<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">


<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />

<android.support.v7.widget.Toolbar
android:id="@+id/detail_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_collapseMode="pin"/>


</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

但是,当我尝试设置标题和副标题时,工具栏中只显示标题!

private void setupToolbar(){
toolbar = (Toolbar) findViewById(R.id.detail_toolbar);
if(toolbar != null){
setSupportActionBar(toolbar);
}

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(mTitle);
getSupportActionBar().setSubtitle("Subtitle);
}

如何访问工具栏的副标题?

最佳答案

这是一个 CollapsingToolbarLayout 错误。

阅读 http://saulmm.github.io/mastering-coordinator并参观一些图书馆:

https://github.com/anton46/WhatsApp-ProfileCollapsingToolbar ,

https://github.com/hendraanggrian/collapsingtoolbarlayout-subtitle ,

https://github.com/ahmadmuzakki/subtitle-collapsingtoolbar

https://github.com/k0shk0sh/CoordinatorLayoutExample或您喜欢的任何其他人。

您还可以阅读我关于 Android 4.4 中阴影的回答:https://stackoverflow.com/a/48526318/2914140 .

更新

目前我可以看到已删除的答案。也许它会帮助某人。从源代码复制粘贴 (@q126y)。

这是因为在调用 setSubtitle 时工具栏尚未呈现。

这样调用代码。

mToolbar.post(new Runnable() {
@Override
public void run() {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(mTitle);
getSupportActionBar().setSubtitle("Subtitle");
}
});

关于android - 工具栏副标题不出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32785454/

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