简体   繁体   English

使用CollapsingToolBarLayout看不到工具栏标题

[英]Toolbar title not visible with CollapsingToolBarLayout

<android.support.design.widget.AppBarLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <!--    ******************    TOOLBAR    *******************    -->
    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|snap"

        >
        <android.support.v7.widget.Toolbar
            app:layout_scrollFlags="scroll|enterAlways|snap"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/toolbar"
            >
        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.CollapsingToolbarLayout>

Hello everyone. 大家好。 My toolbar is not visible even though I have set it in my activity with: 即使在活动中使用以下工具设置了我的工具栏,它也不可见:

(toolbar.setTitle("TITLE");
        toolbar.setTitleTextColor(0xFFFFFF);

I have provided a snip of my .XML file. 我提供了.XML文件的片段。 Since I am a noob, I'm requesting the stackoverflow army for help. 由于我是菜鸟,因此我向Stackoverflow军队寻求帮助。

Thanks a lot for helping me out. 非常感谢您的帮助。

If you need to set in in your Activity you can use support action bar like this. 如果您需要在“活动”中进行设置,则可以使用类似这样的支持操作栏。

on onCreate on onCreate

     setSupportActionBar(toolbar);

then later when you are going to set your title try this. 然后,当您要设置标题时,请尝试此操作。

     if (getSupportActionBar() != null) {
        if (title!=null) {
            getSupportActionBar().setDisplayShowTitleEnabled(true);
            getSupportActionBar().setTitle(title);
        } else {
            getSupportActionBar().setDisplayShowTitleEnabled(false);
        }
    }

If not you may use xml option too: 如果没有,您也可以使用xml选项:

    <android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:title="TITLE"
    app:popupTheme="@style/AppTheme.PopupOverlay">

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CollapsingToolbarLayout标题不进入工具栏 - CollapsingToolbarLayout title not letting into toolbar CollapsingToolbarLayout中的工具栏,工具栏标题未显示 - Toolbar inside CollapsingToolbarLayout, Toolbar title not showing 在CollapsingToolbarLayout中,工具栏在折叠状态下不可见 - Toolbar not visible in collapsed state inside CollapsingToolbarLayout CollapsingToolbarLayout折叠时未显示工具栏标题 - Toolbar Title not showing when CollapsingToolbarLayout collapsed 如何在CollapsingToolbarLayout中更改工具栏标题的字体? - How to change the font of toolbar title in CollapsingToolbarLayout? CollapsingToolbarLayout + TabLayout,奇怪的工具栏标题边距 - CollapsingToolbarLayout + TabLayout, strange toolbar title margin 在Android的CollapsingToolbarLayout中更改工具栏标题的字体大小 - Change font size of Toolbar title in CollapsingToolbarLayout in android 如何在CollapsingToolbarLayout内的工具栏中固定标题 - how to pin title in Toolbar inside CollapsingToolbarLayout 标题在自定义工具栏中不可见 - Title not visible in Custom Toolbar 未折叠时,工具栏的某些部分在CollapsingToolbarLayout的ImageView上可见 - When not collapsed some part of the the toolbar is visible over the ImageView of CollapsingToolbarLayout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM