嗨,有人知道如何使用AndroidX库中的浮动操作按钮吗?我认为在AndroidX库中,它们替换了
implementation 'com.android.support:appcompat-v7:xx.xx.xx'
implementation 'androidx.appcompat:appcompat:1.0.0'
但是这并没有帮助,有任何建议吗?
嗨,有人知道如何使用AndroidX库中的浮动操作按钮吗?我认为在AndroidX库中,它们替换了
implementation 'com.android.support:appcompat-v7:xx.xx.xx'
implementation 'androidx.appcompat:appcompat:1.0.0'
但是这并没有帮助,有任何建议吗?
要在 AndroidX 库中使用浮动操作按钮,请使用以下 dependencies
implementation 'com.google.android.material:material:1.0.0-rc01'
更多信息请查看迁移到AndroidX
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" />
app:tint="@android:color/white"
用于改变FloatingActionButton
的图标颜色。
app:backgroundTint="@color/colorAccent"
用于改变FloatingActionButton
的背景颜色。在活动或片段中使用
FloatingActionButton
,我们需要像这样导入FloatingActionButton
。
import com.google.android.material.floatingactionbutton.FloatingActionButton
<com.google.android.material.floatingactionbutton.FloatingActionButton ... />
同时在gradle文件中添加:
implementation 'com.google.android.material:material:1.0.0'
要在AndroidX库中使用浮动操作按钮,请使用以下实现方式
implementation 'com.google.android.material:material:1.0.0'
app:layout_constraintBottom_toBottomOf
、app:layout_constraintEnd_toEndOf
、app:layout_constraintStart_toStartOf
、app:layout_constraintTop_toTopOf
。只需从您的代码中删除此内容,并根据您的要求应用约束即可。 - AskNilesh