Android FloatingActionButton has display exception

Rendering exception:

Color value '?attr/colorAccent' must start with # (2 similar errors not shown) 

What does it mean? The documentation is not very good in the support library. Does anyone have a good example of how to implement a FloatingActionButton?

+5
source share
4 answers

try choosing a color for your Fab like this:

 fab:button_color="@android:color/holo_blue_bright" 

Take a look at my full implementation.

 <com.software.shell.fab.FloatingActionButton android:id="@+id/sub_category_fab" fab:type="DEFAULT" android:visibility="visible" fab:button_color="@android:color/holo_blue_bright" fab:image="@mipmap/ic_add_white_24dp" fab:image_size="@dimen/fab_image_size" fab:hide_animation="@anim/fab_roll_to_right" fab:show_animation="@anim/fab_roll_from_down" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="false" android:layout_alignParentRight="true" android:layout_alignParentBottom="true" android:layout_margin="@dimen/fab_margin" /> 
+1
source

It looks like he is looking for a HEX code for a color (e.g. #FF0000 ). The value of ?attr/colorAccent may return null .

Try substituting the actual color (HEX code) for the value.

0
source

Add the missing colors to the AppBaseTheme and the error will disappear:

 <style name="AppBaseTheme" parent="@android:style/Theme.Material.Light.DarkActionBar"> ... <item name="colorAccent">@color/your_accent_color</item> <item name="colorControlHighlight">@color/your_ch_color</item> </style> 
0
source

In my opinion, this is a mistake in the design library. I have the same exception that occurs during rendering (in the designer’s view), but a floating button works at runtime. Moreover, app:fab_colorNormal and other attributes related to fab are not considered in the preview, and there is also a strange square shadow around the button.

All this is not consistent with the actual performance: when I test on both a real and an emulated device, the button behaves as expected

0
source

All Articles