android - 展开包含 EditText 的工具栏

标签 android android-toolbar

我第一次接触展开/折叠工具栏。我在 this great tutorial 之后得到了一些结果.

现在,我想(如果可能的话)替换静态标题(参见下面的标题“Anthoriro”)

enter image description here

几个 EditText 所以我有类似的东西

enter image description here

在这种情况下,折叠工具栏时显示的文本将是标题Project Priorities

最佳答案

像这样创建你的布局

   <android.support.design.widget.CoordinatorLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/htab_maincontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true">

            <android.support.design.widget.AppBarLayout
                android:id="@+id/htab_appbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

                <android.support.design.widget.CollapsingToolbarLayout
                    android:id="@+id/htab_collapse_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    android:fitsSystemWindows="true"
                    app:contentScrim="?attr/colorPrimary"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed">

                    <RelativeLayout
                        android:id="@+id/htab_header"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:fitsSystemWindows="true"
                        app:layout_collapseMode="parallax"
                        >

                        <EditText
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:inputType="text"
                            android:ems="10"
                            android:id="@+id/editText2"
                            android:hint="Title"
                            android:text="Project"
                            android:layout_centerVertical="true"
                            android:layout_centerHorizontal="true"/>

                        <EditText
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Name"
                            android:ems="10"
                            android:id="@+id/editText3"
                            android:layout_below="@+id/editText2"
                            android:layout_alignLeft="@+id/editText2"
                            android:layout_alignStart="@+id/editText2"
                            android:layout_marginTop="28dp"
                            android:inputType="text"/>
                    </RelativeLayout>

                    <android.support.v7.widget.Toolbar
                        android:id="@+id/mToolbar"
                        android:layout_width="match_parent"
                        android:layout_height="56dp"
                        android:gravity="top"
                        android:minHeight="?attr/actionBarSize"
                        app:layout_collapseMode="pin"
                        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                        />


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


       <--Swap this with your scrollable view -->

            <android.support.v4.view.ViewPager
                android:id="@+id/mViewPager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
        </android.support.design.widget.CoordinatorLayout>

在你的 Activity/fragment 集中

//Dont forget to find your CoolapsingLayout first :)

//set The custom text
mCollapisngToolbar.setTitle("TEXTTTs");

//Set the color of collapsed toolbar text
mCollapisngToolbar.setCollapsedTitleTextColor(ContextCompat.getColor(this, R.color.White));

//This will set Expanded text to transparent so it wount overlap the content of the toolbar          
mCollapisngToolbar.setExpandedTitleColor(ContextCompat.getColor(this, R.color.Transparent));

关于android - 展开包含 EditText 的工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37783194/

相关文章:

java - GcmListenerService 客户端通知

android - 指定航路点时,Direction API 仅返回一条路线

java - 无法在此方法中找到对返回值的引用

android - 从 ICS ActionBar 切换到 Lollipop 工具栏后缺少导航图标

android - 如何更改自定义操作栏上菜单图标的颜色?

Android Lollipop 工具栏在打开/关闭抽屉和后退按钮之间切换

Android Assets 、C、JNI

android - CollapsingToolbarLayout 在 4.4 设备上崩溃 (java.lang.IllegalArgumentException : radius must be > 0)

android - 从 fragment 中禁用抽屉导航

java - Android如何开始系列动画