Coder Social home page Coder Social logo

Comments (20)

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 21, 2024

There is a similar library that managed to add the ripple effect here:
https://github.com/makovkastar/FloatingActionButton
Perhaps it can be useful?

from android-floating-action-button.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 21, 2024

OK, I've found out how to add this, but I'm not sure how to offer the change on Github (fork?), so I will tell you what needs to be done here:

attrs.xml:
add this attribute to "FloatingActionButton":

    <attr name="fab_colorRipple" format="color" />

FloatingActionButton.java :

add field:

 private int mColorRipple;

inside init() method , add this:

mColorRipple = attr.getColor(R.styleable.FloatingActionButton_fab_colorRipple, getColor(android.R.color.white));

and add/change those methods:

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private void setBackgroundCompat(Drawable drawable) {
    if (Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
        RippleDrawable rippleDrawable = new RippleDrawable(new ColorStateList(new int[][]{{}},
                new int[]{mColorRipple}), drawable, null);
        setBackground(rippleDrawable);
    } else if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN)
        setBackground(drawable);
    else
        setBackgroundDrawable(drawable);
}

public void setColorRipple(int color) {
    if (color != mColorRipple) {
        mColorRipple = color;
        updateBackground();
    }
}

public void setColorRippleResId(@ColorRes int colorResId) {
    setColorRipple(getColor(colorResId));
}

public int getColorRipple() {
    return mColorRipple;
}

It works fine, but I think that the shadow gets a ripple too, and that the inner icon image should have a ripple.
Also, I suggest using elevation when possible, instead of the shadow that's used. Check this link:
https://github.com/makovkastar/FloatingActionButton/blob/master/library/src/main/java/com/melnykov/fab/FloatingActionButton.java

from android-floating-action-button.

afollestad avatar afollestad commented on July 21, 2024

+1

from android-floating-action-button.

mkay007 avatar mkay007 commented on July 21, 2024

+1

from android-floating-action-button.

Mygod avatar Mygod commented on July 21, 2024

+1

from android-floating-action-button.

chris-horner avatar chris-horner commented on July 21, 2024

+1

from android-floating-action-button.

Poeschl avatar Poeschl commented on July 21, 2024

+1

from android-floating-action-button.

S2V avatar S2V commented on July 21, 2024

+1, will be very useful

from android-floating-action-button.

PaulWoitaschek avatar PaulWoitaschek commented on July 21, 2024

+1.

Material without ripples?

from android-floating-action-button.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 21, 2024

For those who used what I wrote, has anyone had any issues with it?
I got a very rare issue which might be because of what I did:
#175

from android-floating-action-button.

droidwithme avatar droidwithme commented on July 21, 2024

@AndroidDeveloperLB its not working.

from android-floating-action-button.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 21, 2024

@Devendrasingh91 Maybe try one of these solutions (got the tip from: https://plus.google.com/+NickButcher/posts/azEU6s4APbu ) :

1.Wrap the drawable in a RippleDrawable² before setting it on the ImageView:

Drawable image = …
RippleDrawable rippledImage = new RippleDrawable(ColorStateList.valueOf(rippleColor), image, null);
imageView.setImageDrawable(rippledImage);

2.Extend ImageView and add a foreground attribute to it (like FrameLayout has³). See this example⁴ from +Chris Banes of adding it to a LinearLayout. If you do this then make sure you pass through the touch co-ordinates so that the ripple starts from the correct point:

@OverRide
public void drawableHotspotChanged(float x, float y) {
super.drawableHotspotChanged(x, y);
if (foreground != null) {
foreground.setHotspot(x, y);
}
}

from android-floating-action-button.

droidwithme avatar droidwithme commented on July 21, 2024

please simplify a bit more, i am not understanding, where i can write this code. and the co-ordinates.

from android-floating-action-button.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 21, 2024

@Devendrasingh91 What to explain more exactly ? What didn't you understand ?
Anyway, I've forked the project just to add this code, here:
https://github.com/AndroidDeveloperLB/android-floating-action-button

I'm sure there are better solutions than what I did.

from android-floating-action-button.

droidwithme avatar droidwithme commented on July 21, 2024

i wanted to make such effect.. like if we click a floatmenubutton than the whole layout should get the effect(in which the parent layout get the ripple effect's color.) than goes to next activity as i have to go on another page. may be this will work on Api21, but what about lower verisons? @AndroidDeveloperLB

from android-floating-action-button.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 21, 2024

@Devendrasingh91 I don't understand. Maybe you mean this:
ViewAnimationUtils.createCircularReveal()

example:
https://halfthought.wordpress.com/2014/12/02/reveal-activity-transitions/

from android-floating-action-button.

Poeschl avatar Poeschl commented on July 21, 2024

I use for that this fab: https://github.com/Clans/FloatingActionButton

It has a few more features.

from android-floating-action-button.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 21, 2024

@Poeschl Google also added its own, for the new library they've published.

from android-floating-action-button.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 21, 2024

any news about this?

from android-floating-action-button.

mmoczkowski avatar mmoczkowski commented on July 21, 2024

+1

from android-floating-action-button.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.