I've just started android development and trying the new material design. is a screenshot of my mainactivity which has a FloatingActionButton but it doesnt applying any elevation (no shadows).
How can I enable shadow on this new widget (android.support.widget.FloatingActionButton).
This is code from layout xml
<android.support.design.widget.FloatingActionButton
android:id="#+id/add_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="#drawable/ic_add_action"
android:layout_margin="16dp"
android:elevation="10dp"
android:padding="10dp"/>
Any help appreciated. Thanks
Please note I'd like to use android design library only not any other github libraries.
After a lot of research, I've found the proper way to use FAB with no issues. Use the code below as template:
<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/your_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="#dimen/floating_button_margin_bottom"
android:layout_marginRight="#dimen/floating_button_margin_right"
app:elevation="#dimen/floating_button_elevation"
app:borderWidth="0dp"
app:rippleColor="#color/your_ripple_color"
app:backgroundTint="#color/your_bg_color" />
I'm just testing the floating action button now. And for me it works.
Try adding app:borderWidth="0dp" for your button, this might solve the problem.
I saw in some other posts that it might be a problem in the design library.
Your XML layout might missed these code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
app:xmlns="http://schemas.android.com/apk/res-auto"
... >
<android.support.design.widget.FloatingActionButton
...
app:borderWidth="0dp"
app:elevation="4dp" />
...
</RelativeLayout>
EDIT
For more information about FloatingActionButton, see this post, which explains the issue and design guide.
Check the manifest file and delete the next properties:
android:hardwareAccelerated="false"
android:largeHeap="true"
Related
I try to give my FloatingActionButton a background color different than that defined as accentColor in my style. So far I try to do this:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginEnd="16dp"
android:layout_marginBottom="#dimen/margin_bottom"
android:backgroundTint="#color/primaryColor"
android:clickable="true"
android:focusable="true"
app:srcCompat="#drawable/ic_baseline_add_24" />
Where this is inside a CoordinatorLayout. This is what i get:
As you can see there is a blue circle around the fab. I don't know how to get rid of it. I also tried to define a style for this fab, but then i got black and it messed up completely. I think it could have to do something with its shadow, but I also don't know how to change it without changing elevation.
Pleas Try this code its use full
<com.rey.material.widget.FloatingActionButton
android:id="#+id/user_add_item_to_card"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_gravity="end"
app:fab_iconSrc="#drawable/ic_add_circle_black_24dp"
app:borderWidth="0dp"
android:background="#FFF">
</com.rey.material.widget.FloatingActionButton>
After a little bit more trying out I got the solution:
You just need to add app:borderWidth="0dp" and it's gone.
Other way to do it is to use app:backgroundTint="".
I am currently working on an Android app and using the latest addition of the Floating Action Button. However, after compiling the necessary libraries and adding the fab into my xml file, it appears as a square while I am expecting it to be a circle, just like everywhere else.
I use the same basic code to implement the fab as found online and my result is a square and theirs is a nice circle fab.
Here is my code:
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="16dp"
android:src="#drawable/ic_person_add_black_24dp" />
Here is an screenshot of what is displayed:
How to display the fab (add contact here) as a circle?
Thank you,
Try to set one of appcompat themes for your fab or either for the parent layout: android:theme="#style/Theme.AppCompat"
I don't know if this is what solved it but I stopped working on this project for another one for a little bit & I didn't have this problem on my other project.
AndroidStudio seems to create a square fab if your activity extends Activity and not AppCompatActivity.
Even if your activity extends AppCompatActivity you may also need to build the project (Ctrl+F9) before you can see the preview properly rendered.
Try this XML code, This is auto-generated code by Android studio from the template
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#android:drawable/ic_dialog_email" />
Hope this helps.
You can use material FAB with Theme.MaterialComponents
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="#+id/fab_Send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:contentDescription="#string/app_name"
android:gravity="center"
android:text="#string/send"
android:theme="#style/Theme.MaterialComponents"
android:textAllCaps="false"
android:textColor="#color/colorWhite"
android:textSize="#dimen/_12sdp"
app:backgroundTint="#color/colorPrimary"
app:borderWidth="0dp"
android:fontFamily="#font/play_fair_display_black"
app:useCompatPadding="true"
tools:ignore="RelativeOverlap" />
Here is the result
The reason why this happens is that, you are using a different theme for you app other than that is used by the FAB. In my case I am using Theme.AppCompat.Light.NoActionBar for my app but FAB does not supported by this.
Rendering Problems Couldn't resolve resource #id/search_edit_frame
This is the rendering error I'm getting in my xml file. I think it has something to do with my support.v7.SearchView below is my xml:
<RelativeLayout
android:id="#+id/layout_ricerca"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/search_border_backgroud"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="20dp">
<android.support.v7.widget.SearchView
android:id="#+id/testo_ricerca"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:queryHint="#string/search_hint"
android:textSize="25sp"
android:layout_marginStart="5dp"
android:iconifiedByDefault="false"/>
<ImageButton
android:id="#+id/tasto_ricerca"
android:background="#color/trans"
android:layout_marginTop="2dp"
android:layout_width="45dp"
android:layout_height="match_parent"
android:layout_marginEnd="3dp"
android:scaleType="centerInside"
android:layout_alignParentEnd="true"
android:src="#drawable/tasto_ricerca"/>
</RelativeLayout>
When I change the <android.support.v7.widget.SearchView to <SearchView the error disappears, but that's not a good solution for me because I would have to change all my java code to work with the SearchView instead of the android.support.v7.widget.SearchView.
Does anyone know how to fix this problem ? why does it happen? I don't think there is anything wrong with my xml.
Edit:
Added screenshot of the error
To resolve this issue, provide an
android:id="#+id/search_edit_frame"
attribute to a parent view such as
android.support.design.widget.AppBarLayout
or any ViewGroup that is parent to your SearchView.
For example:
<android.support.design.widget.AppBarLayout
android:id="#+id/search_edit_frame"
android:layout_width="match_parent"
android:layout_height="#dimen/my_app_bar_height">
<android.support.v7.widget.SearchView
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.AppBarLayout />
When you have lot of cache memory data are store in Android Studio that time this type of error is coming..
There are many way to solve it.
Quickest way to do that is File → Invalidate caches / Restart...
→ Just Restart.
Right click on project and Synchronize ...Project
click on Build menu --> select Clean Project and then Rebuild
it.
use this code
<SearchView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/searchView"
android:iconifiedByDefault="true"
android:queryHint="Search"
android:layout_centerHorizontal="true" />
android:id="#+id/search_edit_frame"
add above line to parent layout that did the trick for me
Here is an easy one solution.
There is no need of invalidating cache Or restarting.
Just add below line into your strings.xml file and problem will get solved.
<item name="search_edit_frame" type="id"/>
Bingo!
I have the same problem but in eclipse IDE and I solved it by
1- click on project --> clean and it solved the problem with me
I wanted to implement a floating action button in android studio and I followed all the steps: Adding dependencies, adding the xmlns to the layout and making the floatingbuttion in the xml as follows:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.clans.fab.FloatingActionButton
android:id="#+id/fab"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_gravity="bottom|right"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
fab:fab_colorNormal="#color/primary"
fab:fab_colorPressed="#color/accent"
fab:fab_colorRipple="#color/primary_dark" />
</FrameLayout>
but in the preview I got a gray, empty square. What am I doing wrong?
I am not sure, but I think you have to include a src
Please reply if it helped you!
<android.support.design.widget.FloatingActionButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/fab"
android:src="#drawable/abc_ic_search_api_mtrl_alpha"
android:layout_alignBottom="#+id/recyclerview"
android:layout_alignRight="#+id/recyclerview"
android:layout_alignEnd="#+id/recyclerview" />
Please add the code "app:borderWidth="0dp" as property.
This question already has answers here:
FloatingActionButton, square button below API level 17
(6 answers)
Closed 3 years ago.
The new android design library provides the android.support.design.widget.FloatingActionButton to make it easier to implement a floating action button.
But the button is always a circle.
I received from the company designer a square floating button concept, but I can't find any reference to change the background of the android.support.design.widget.FloatingActionButton to have a square background.
Note: If I use a custom custom drawable the background still have the circle, like this:
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_filter"
app:layout_anchor="#+id/appbar"
app:layout_anchorGravity="bottom|right|end" />
I try to use a simple Button, but it seems to break the toolbar size when it was collapsed:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:elevation="10dp"
android:background="#drawable/button_filter"
app:layout_anchor="#+id/appbar"
app:layout_anchorGravity="bottom|right|end" />
Is possible to have a square button using the FloatingActionButton with the new Android Design Library?
The problem is the "android:background", look at the template below and notice the "app:backgroundTint", use it as template and it should work:
<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/your_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="#dimen/floating_button_margin_bottom"
android:layout_marginRight="#dimen/floating_button_margin_right"
app:elevation="#dimen/floating_button_elevation"
app:borderWidth="0dp"
app:rippleColor="#color/your_ripple_color"
app:backgroundTint="#color/your_bg_color" />
Alright, using use the attribute app:borderWidth="0dp" in the FloatingActionButton solved the problem.
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_filter"
app:layout_anchor="#+id/appbar"
app:borderWidth="0dp"
app:layout_anchorGravity="bottom|right|end" />