Floating Action Button for lower version - android

Is there a way I can Achieve the floating button to work on 4.0 and later android??
I've seen it on google plus but I haven't found any tutorial. Only for android l preview. What did google+ use to achieve it?

You can now use the FloatingActionButton from the support-design library. Add this dependency to your gradle build file:
compile 'com.android.support:design:22.2.0'
And then add the FloatingActionButton to your layout file:
<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="#dimen/fab_margin"
android:src="#drawable/ic_done" />
Example project from Chris Banes: https://github.com/chrisbanes/cheesesquare.

I created an open-source library called FloatingActionButton. It's a Google+ like floating action button which reacts on the list view scrolling events. Becomes visible when the list view is scrolled up and invisible when scrolled down. API level 14+.

Here is one aditional free Floating Action Button library for Android
It has many customizations and requires SDK version 9 and higher
Full Demo Video
dependencies {
compile 'com.scalified:fab:1.1.2'
}

Original post is here.
You can use this library, it works well from the Android 2.1, API level 7.
It's so easy to include it in your project:
build.gradle
dependencies {
compile 'com.shamanland:fab:0.0.6'
}
layout.xml
<com.shamanland.fab.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/your_image"
/>

You can use this demo FloatingView. This demo work from API 11.
Here put all the parts necessary to implement by code. FloatingView by steps

Try this library, https://github.com/navasmdc/MaterialDesignLibrary
It can be easily to adapt to your project using Android Studio

Related

Android Widget Shadow which supports from API 16

I want to have shadow in Android widget like button, edittext, searchview or anything. I have no idea about android elevation. I think it only supports from API 23. If there is any proper solution then please provide.
here is my demo widget. I need the shadow in border of my searchview.
<android.support.v7.widget.SearchView
android:id="#+id/searchView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroud="#android:color/white" />
You can get the shadow effect by adding this to the widget:
android:background="#android:drawable/dialog_holo_light_frame"
Got the answer from here: https://stackoverflow.com/a/30931750/8466860.
Place your views inside CardView. Using CardView you can add elevation, rounded corners etc. It supports back till API 7.
to use CardView, add it via your app level gradle..
dependencies {
...
compile 'com.android.support:cardview-v7:25.3.1'
}

Android: Set material design elevation for button using AppCompat V7

When following this Android tutorial using AppCompat V7 to get the new Tool Bar work, the android.support.v7.widget.Toolbar supports android:elevation on SDK's < Lollipop. This is because they use android.support.v7.widget.Toolbar and not Toolbar.
Is there equivalent for button? Something like android.support.v7.widget.Button? (This one not exist) Or any other workaround in the kind of overlaying the Button in some view supporting elevation? (I don't want implementation of creating custom shapes with gradients for look & feel of elevation).
Thanks,
You can use the Floating Action Button from support design library .
Use below code to the layout where you want this button.
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_fab"
android:layout_gravity="bottom|end"
app:backgroundTint="#0091b4"
app:elevation="6dp"
app:pressedTranslationZ="12dp"
android:layout_margin="10dp"
android:scaleType="centerCrop" />
Do add design dependency in your project
Add below in the dependency list of build.gradle file
compile 'com.android.support:design:23.0.1'
Unfortunately you will have to do what you do not want. Because there is no support button view yet. (As i know :) perhaps some omniscient person will correct my answer)

How to add a Floating Action Button, without AppCompat?

I'm looking to make a new app, using only API 21.
To follow the Material Design, I'm trying to use a FAB, but I cannot find any decent information on how to use the one now included in the Design Library.
So far, I have added the library the the build.gradle file, and added a FAB to my view (code below)
<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:src="#android:drawable/ic_menu_add"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
app:elevation="5dp"
app:borderWidth="0dp"
app:fabSize="mini"/>
(This is in a RelativeLayout)
When I launch the app, I get:
android.view.InflateException: Binary XML file line #15: Error
inflating class android.support.design.widget.FloatingActionButton
I found one answer on SO that says I need to use an AppCompat theme, but I'd rather just use pure Material/API21 stuff.
How can I use a FAB without AppCompat (support libraries)?
The FAB is built into the new Design Compat library - which will work on devices as early as API 7. You will need to include it as a dependency to use it (and shouldn't hesitate to do so).
If you want to avoid using a library (or any external code) you will need to draw the FAB yourself (using a Shape Drawable).
Bottom line, using the Design Compat lib is the preferred method for supporting a FAB, and you should use it. The Design Compat lib IS the "pure/Material API21 stuff".
There is NOT a FAB implementation implemented for any API other then the one in the Design support lib. You have to include the lib, or implement the code entirely yourself.
The Design lib has a dependency on AppCompat, so if you are planning on using the native fab, you will also need to include the dependency for AppCompat.
From the official blog post: "Note that as the Design library depends on the Support v4 and AppCompat Support Libraries, those will be included automatically when you add the Design library dependency."
The Material Design library has a dependency with AppCompat.
Check the #Booger answer. It reports the official blog.
How to use a FAB.
Add the dependency to your build.gradle:
compile 'com.android.support:design:22.2.0'
Just add the FAB to your design:
<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:src="#drawable/ic_add"
android:layout_marginBottom="#dimen/fab_margin_bottom"
android:layout_marginRight="#dimen/fab_margin_right"
app:elevation="6dp"
app:borderWidth="0dp"
app:fabSize="normal" />
Currently there are some bugs.
You have to define app:borderWidth="0dp" to display the shadow with API21+.
Also you have to define different margins for API 21+ and older devices.
res/values/dimens.xml
<dimen name="fab_margin_right">0dp</dimen>
<dimen name="fab_margin_bottom">0dp</dimen>
res/values-v21/dimens.xml
<dimen name="fab_margin_right">16dp</dimen>
<dimen name="fab_margin_bottom">16dp</dimen>
FAB uses the accent color and you could override with app:backgroundTint attribute.
Finally you can set a ClickListener with:
fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//do something
}
});
Actually I was having the same problem. The solution was quite simple:
you have to define app:rippleColor="#color/colorPrimary"
and you can use a FAB without using Appcompat Themes and Activities. Of course you have to include compile 'com.android.support:support-v4:25.3.1' and compile 'com.android.support:design:25.3.1'
but you DO NOT have to use AppCompatActivity and those Themes.
<android.support.design.widget.FloatingActionButton
android:id="#+id/action_add_palette"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:src="#android:drawable/ic_input_add"
app:rippleColor="#color/colorPrimary" />
There is also several popular libraries on GitHub like:
FloatingActionButton which can expand/collapse as menu to reveal multiple actions.
I would say that although you intend to make your app available on API21 only but I encourage you to implement your application using Android Support Library AppCompat-v7 anyway. There are a lot of benefits you will get.
Anyway it is your choice. Just my suggestion. But if you are convinced. Or check out this full tutorial about how to use Android Design Support Library. http://inthecheesefactory.com/blog/android-design-support-library-codelab/en
Hope this help

How to create a circle button in the right bottom corner on Android 5+?

Is there any standard tools or existing libraries to create a circle button like on Gmail App?
In the android support design support library one of the widgets provided is the Floating Action Button, which is usually added in the bottom right corner(but need not be used only there)
A floating action button is a round button denoting a primary action
on your interface. The Design library’s FloatingActionButton gives you
a single consistent implementation, by default colored using the
colorAccent from your theme.
To get the android design support library in your build.gradle file, add this:
compile 'com.android.support:design:22.2.0'
In your layout file"
<RelativeLayout
...
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.FloatingActionButton
android:id="#+id/myFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="#id/appbar"
app:layout_anchorGravity="bottom|right|end"
android:src="#drawable/ic_discuss"
android:layout_margin="10dp"
android:clickable="true"/>
</RelativeLayout>
Details of android design support library here
Also there are many other libraries providing the FAB like
https://github.com/makovkastar/FloatingActionButton
https://github.com/futuresimple/android-floating-action-button
1.First important thing use Android Studio
2.Add as a dependency to your build.gradle:
dependencies {
compile 'com.melnykov:floatingactionbutton:1.3.0'
}
3. Create a layout
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.melnykov.fab.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="#drawable/ic_action_content_new"
fab:fab_colorNormal="#color/primary"
fab:fab_colorPressed="#color/primary_pressed"
fab:fab_colorRipple="#color/ripple" />
4.Add the namespace
xmlns:fab="http://schemas.android.com/apk/res-auto"
to your layout file.
You can also Set the button type (normal or mini) via the fab_type xml attribute (default is normal):
fab:fab_type="mini"
or
fab.setType(FloatingActionButton.TYPE_MINI);
Yes, with the new Design Support Library a default implementation of the floating action button is provided here.
In order to have access to the new FAB class you will need to add this dependency to your gradle build file.
compile 'com.android.support:design:22.2.0'

Unknown attribute android:elevation

I'm trying to follow a tutorial that suppose to show how to add a floating button and in the tutorial it says to add the attribute android:elevation to the buttons xml like this:
<ImageButton
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/editButton"
android:layout_gravity="center|right"
android:clickable="false"
android:background="#drawable/edit_grey"
android:layout_marginRight="1dp"
android:elevation="#dimen/elevation_low"/>
but it dosen't recognize that attribute...i believe it has something to do with my project target or sdk...can somebody help me?
To use android:elevation, just as with any other Android 5.0 API, you must compile against Android 5.0 (API 21). This does not mean you have to change your target SDK level or minimum SDK level.
Note: your XML file may still give a warning that android:elevation only works on Android 5.0 or higher. This warning just serves to tell you that previous versions of Android will not have an elevation shadow on the floating action button. However, that does not cause an error - previous versions of Android will ignore XML attributes they do not understand.
The Elevation attribute is pretty new. It defines the lift of the view it is applied to. It is used for the Material Design in the newest Android Versions.
Material Design
You can use it on API Level 21, I guess your targeted Level is lower than this.
If you just want to achieve some shadowing you can use this:
Shadow Drawables for Views
Or you can use the SupportLibrary with CardViews or something like that, they support elevation from API Level 7:
[How-to] Use the v21 Support Libs on Older Versions & Target L While Remaining Backwards-Compatible
Hope this helps.

Categories

Resources