简体   繁体   English

andoidx库中的浮动动作按钮

[英]Floating action button in andoidx library

Hi is there anyone knows how to use the floating action button with andoidx library I think in android x library they replace嗨,有没有人知道如何使用带有 andoidx 库的浮动动作按钮,我认为在他们替换的 android x 库中

implementation 'com.android.support:appcompat-v7:xx.xx.xx'

by经过

implementation 'androidx.appcompat:appcompat:1.0.0'

but it's not helping any suggetion?但它没有帮助任何建议?

To use Floating action button in andoidx library use below dependencies要在 andoidx 库中使用浮动操作按钮,请使用以下dependencies

implementation 'com.google.android.material:material:1.0.0-rc01'

For more information check Migrating to AndroidX有关更多信息,请查看Migrating to AndroidX

Complete example完整示例

XML code XML 代码

<com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/imgFour"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_close"
        app:backgroundTint="@color/colorAccent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:tint="@android:color/white" />

Notes笔记

app:tint="@android:color/white" is used to change the icon color of FloatingActionButton app:tint="@android:color/white"用于改变FloatingActionButton的图标颜色

app:backgroundTint="@color/colorAccent" is used to change background color of FloatingActionButton app:backgroundTint="@color/colorAccent"用于改变FloatingActionButton background颜色

To use FloatingActionButton inside activity or fragment we need to import FloatingActionButton like this要在活动或片段中使用FloatingActionButton我们需要像这样导入FloatingActionButton

import com.google.android.material.floatingactionbutton.FloatingActionButton

Now you can migrate to Android x and replace the xml with:现在您可以迁移到 Android x 并将 xml 替换为:

<com.google.android.material.floatingactionbutton.FloatingActionButton ... />

Also in the gradle file add:同样在 gradle 文件中添加:

implementation 'com.google.android.material:material:1.0.0'

要在 androidx 库中使用浮动操作按钮,请使用此实现

implementation 'com.google.android.material:material:1.0.0'

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM