如何在 android 中实现扩展浮动操作按钮
how can implement Extended Floating Action Button in android
这么多参考文献解释了extended-floating-action-button
要使用此功能,必须将 android studio 与 androidx 合并并添加
implementation 'com.google.android.material:material:1.1.0-alpha04'
库 >= 4 并且必须将扩展浮动操作按钮放入 CooordinatoriLayout
我做的每件事都是对的,过去有很多问题,比如
The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
但已修复
更改父级样式
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
现在我在布局中正确地看到了扩展浮动操作按钮
但仍然无法使用扩展浮动操作按钮
当 运行 项目
得到这个错误
Error inflating class com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
带有描述 The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
我对此做了很多研究,但没有好的和完整的参考或教程,我想知道世界上任何人都可以使用这个功能吗?
UPDATED
problem came from parent layout! android:theme="@style/AppTheme" must
be added in parent layout
您在布局中使用 appcompat 主题 styles.xml 像这样
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
将其更改为这些行
<style name="AppTheme" parent="Theme.MaterialComponents">
之后,您在布局中导入该样式
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:orientation="vertical"
android:theme="@style/AppTheme"//here is the xml layout root tag>
对不起,我忘记了主要的事情
<application
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
你也必须这样做。
并且不要在同一布局中使用 appcompat 和 material 主题,请
这么多参考文献解释了extended-floating-action-button
要使用此功能,必须将 android studio 与 androidx 合并并添加
implementation 'com.google.android.material:material:1.1.0-alpha04'
库 >= 4 并且必须将扩展浮动操作按钮放入 CooordinatoriLayout
我做的每件事都是对的,过去有很多问题,比如
The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
但已修复
更改父级样式<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
现在我在布局中正确地看到了扩展浮动操作按钮
但仍然无法使用扩展浮动操作按钮
当 运行 项目
得到这个错误
Error inflating class com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
带有描述 The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
我对此做了很多研究,但没有好的和完整的参考或教程,我想知道世界上任何人都可以使用这个功能吗?
UPDATED
problem came from parent layout! android:theme="@style/AppTheme" must be added in parent layout
您在布局中使用 appcompat 主题 styles.xml 像这样
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
将其更改为这些行
<style name="AppTheme" parent="Theme.MaterialComponents">
之后,您在布局中导入该样式
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:orientation="vertical"
android:theme="@style/AppTheme"//here is the xml layout root tag>
对不起,我忘记了主要的事情
<application
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
你也必须这样做。 并且不要在同一布局中使用 appcompat 和 material 主题,请