浮动操作按钮显示为灰色框
Floating Action Button appears as a gray box
我正在尝试在屏幕的右下角设置一个 FAB,使其漂浮在 recyclerview
的顶部。但是,FAB 只是一个带有小部件路径的灰色框。
问题是:
这是我的 XML 实现:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/userpass_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/generate_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="16dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:clickable="true"
android:focusable="true" />
</RelativeLayout>
依赖关系:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.android.support:design:28.0.1'
implementation 'com.google.android.material:material:1.1.0-alpha05'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
抱歉我没看到图片
我用这个库
implementation 'com.google.android.material:material:1.0.0'
版本号为 1.0.0
您可以尝试清理您的项目缓存并重建它。
尝试file>invalidate caches/restart
。这就是我的一些灰色小部件的问题。
您添加了错误的 FloatingActionButton。
实现这个并添加一个 src 属性。
<android.support.design.widget.FloatingActionButton
android:id="@+id/generate_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_add_black_24dp"/>
尝试使用 ExtendedFloatingActionBar
并将 app:icon
设置为您的 FAB 图标,不要添加任何文本,EFAB 将看起来像 FAB。如果您要将支架放在底部操作栏上,我只是不知道如何像在 FAB 中那样放置支架。
使缓存无效并重新启动,如果它仍然没有正确显示在布局文件中,则 运行 应用程序。一旦你 运行 它,它就会在布局中正确显示 file/preview。
我正在尝试在屏幕的右下角设置一个 FAB,使其漂浮在 recyclerview
的顶部。但是,FAB 只是一个带有小部件路径的灰色框。
问题是:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/userpass_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/generate_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="16dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:clickable="true"
android:focusable="true" />
</RelativeLayout>
依赖关系:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.android.support:design:28.0.1'
implementation 'com.google.android.material:material:1.1.0-alpha05'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
抱歉我没看到图片
我用这个库
implementation 'com.google.android.material:material:1.0.0'
版本号为 1.0.0
您可以尝试清理您的项目缓存并重建它。
尝试file>invalidate caches/restart
。这就是我的一些灰色小部件的问题。
您添加了错误的 FloatingActionButton。 实现这个并添加一个 src 属性。
<android.support.design.widget.FloatingActionButton
android:id="@+id/generate_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_add_black_24dp"/>
尝试使用 ExtendedFloatingActionBar
并将 app:icon
设置为您的 FAB 图标,不要添加任何文本,EFAB 将看起来像 FAB。如果您要将支架放在底部操作栏上,我只是不知道如何像在 FAB 中那样放置支架。
使缓存无效并重新启动,如果它仍然没有正确显示在布局文件中,则 运行 应用程序。一旦你 运行 它,它就会在布局中正确显示 file/preview。