项目作者: GautamGupta

项目描述 :
FAB to Toolbar Button library for Android Material Collapsing Toolbar
高级语言: Java
项目地址: git://github.com/GautamGupta/toolbar-button.git
创建时间: 2016-04-11T05:12:35Z
项目社区:https://github.com/GautamGupta/toolbar-button

开源协议:Apache License 2.0

下载


Toolbar Button Example

Android Toolbar Button Library

The problem with anchoring a floating action button to a collapsing toolbar is that the CTA gets
hidden on scroll. This library allows you to artificially add a button in the toolbar with an
animation as soon as the FAB hides itself.

Works with Android 4.0+ (minSdkVersion 14).

Gradle

  1. dependencies {
  2. ...
  3. compile 'com.android.support:design:25.3.1'
  4. compile 'am.gaut.android.toolbarbutton:toolbarbutton:0.1.0'
  5. }

Usage

Add this at the same level where your floating action button is defined in the activity.
Example.

  1. <am.gaut.android.toolbarbutton.ToolbarButton
  2. android:id="@+id/btn_toolbar_checkin"
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content"
  5. style="?attr/borderlessButtonStyle"
  6. android:background="@drawable/selector_toolbar_button"
  7. android:textAppearance="@style/TextAppearance.AppCompat.Widget.Button.Inverse"
  8. android:paddingLeft="@dimen/toolbar_button_padding"
  9. android:paddingRight="@dimen/toolbar_button_padding"
  10. android:drawablePadding="@dimen/toolbar_button_padding"
  11. android:drawableLeft="@drawable/ic_message_white_18dp"
  12. android:drawableStart="@drawable/ic_message_white_18dp"
  13. android:text="@string/checkin"
  14. app:layout_anchor="@id/appbar"
  15. app:layout_anchorGravity="right|end" ></am.gaut.android.toolbarbutton.ToolbarButton>

You can treat the view as a
Button.
Properties in the snippet produce a similar result as in the screen capture.

@dimen/toolbar_button_padding (16dp), @drawable/selector_toolbar_button
(see,
v21)
are supplied by the library.

@drawable/ic_message_white_18dp is a material icon.

?attr/borderlessButtonStyle and @style/TextAppearance.AppCompat.Widget.Button.Inverse come from
the design support library.

Credits

Troubleshooting

Q. The button hides on scroll. Why is this happening?

The default elevation of 6dp is getting overridden, making it compete with the elevation of the
appbar. Try adding android:elevation="6dp" property on the view.

Q. Does this work for Android versions before 4.0?

It can be made to work for previous Android versions as well, using different implementation classes
like the Floating Action Button. If you take up the initiative, please submit a PR.

License

  1. Copyright 2016 Gautam Gupta
  2. Licensed to the Apache Software Foundation (ASF) under one or more contributor
  3. license agreements. See the NOTICE file distributed with this work for
  4. additional information regarding copyright ownership. The ASF licenses this
  5. file to you under the Apache License, Version 2.0 (the "License"); you may not
  6. use this file except in compliance with the License. You may obtain a copy of
  7. the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. License for the specific language governing permissions and limitations under
  13. the License.