【问题标题】:How do i make an action bar like this我如何制作这样的操作栏
【发布时间】:2015-09-12 00:31:38
【问题描述】:

嗨,我正在制作一个应用程序,我想添加一个活动,就像上面的图片一样,我在操作栏扩展时遇到了困难,我在 google 设计指南上看到了这个,我该如何实现这个在 android lollipop 上(我的最小 sdk 是 21,我对向后兼容性不感兴趣)

提前致谢。

【问题讨论】:

    标签: android android-actionbar material-design android-appcompat android-design-library


    【解决方案1】:

    如果您不想要 CollapsingToolbar ,您可以使用简单的 Toolbar 和自定义 minHeight。

    您可以在工具栏中放置您的视图,例如TextViewTextInputLayout

    最后使用FloatingActionButton。设置属性很重要 app:layout_anchorapp:layout_anchorGravity

     <android.support.design.widget.CoordinatorLayout>
    
          <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar_main"
                android:layout_width="match_parent"
                android:layout_height="256dp"
                android:minHeight="?attr/actionBarSize"
                android:theme="@style/ToolbarMainTheme" >
    
    
               <android.support.design.widget.TextInputLayout>
    
               <TextView>
    
    
           </android.support.v7.widget.Toolbar>
    
    
         <!-- your scrollable view here -->        
    
    
        <android.support.design.widget.FloatingActionButton
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:borderWidth="0dp"
            app:elevation="4dp"
            app:pressedTranslationZ="6dp"
            android:layout_marginRight="@dimen/fab_margin_card"
            android:src="@drawable/ic_youricon"
            app:layout_anchor="@id/toolbar_main"
            app:layout_anchorGravity="bottom|right|end" />
    
    
        </android.support.design.widget.CoordinatorLayout>
    

    【讨论】:

      【解决方案2】:

      这可以通过使用Collapsing Toolbars 来完成,它在android 设计支持library 中提供,这里有一个example 用于了解如何使用该库。

      【讨论】:

      • 但我不想崩溃,有什么方法可以实现吗?
      • @Ang 如果你不喜欢 CollapsingToolbar,你可以使用一个简单的工具栏。检查下面的答案。
      【解决方案3】:

      您只需在布局 xml 的工具栏中添加一个 EditText 和几个 TextView(或将 EditText 包装在 TextInputLayout 中)。

      https://gist.github.com/chris95x8/53214de145571d410e13

      【讨论】:

        猜你喜欢
        • 2015-10-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-26
        • 2014-04-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多