众多参考文献解释了extended-floating-action-button
要使用此功能,必须将android studio与 androidx 合并并添加
implementation 'com.google.android.material:material:1.1.0-alpha04'
库> = 4,并且必须在CooordinatoriLayout中放置extended-floating-action-button
我解决了
之类的许多问题并正确地处理了过去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).
我对此进行了很多研究,但是没有好的和完整的参考文献或教程,我想知道世界上任何人都可以使用此功能吗?
已更新
问题来自父级布局! android:theme =“ @ style / AppTheme”必须 在父级布局中添加
答案 0 :(得分:0)
您正在像这样使用styles.xml在布局中使用appcompat主题
<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和材料主题,请