33=============
44This repository contains post of Android ` <ripple> ` effect for pre lollipop devices with android 14 + (ICS+)
55
6+ (well, since NineOldAndroids is deprecated, this library become 14 + only, furthermore gingerbread devices is not spread now)
7+
68### Features
7- 1 . XML inflating (working on)
9+ 1 . XML inflating
8102 . Ripple supports different shapes
9113 . Custom drawable loader
10124 . Define your custom drawable tags
1113
1214#### Implementation
1315
14- create this file in your drawables/ or drawables-v14/ folder
16+ Create your desirable ripple.xml in ` drawable/ ` folder
17+
1518``` xml
1619<?xml version =" 1.0" encoding =" utf-8" ?>
1720<ripple
1821 xmlns : android =" http://schemas.android.com/apk/res/android"
19- android : color =" @color/ripple_material_light" >
22+ android : color =" @color/ripple_material_light" > <!-- ripple color -->
2023
21- <!-- for fab -->
24+ <!-- for Floating Action Button -->
2225 <item >
2326 <shape android : shape =" oval" >
2427 <solid android : color =" @color/accent_material_dark" />
@@ -29,6 +32,64 @@ create this file in your drawables/ or drawables-v14/ folder
2932
3033```
3134
35+ Secondly we need to inflate ` RippleDrawable ` and intercept ` View ` touches
36+ see ` LollipopDrawablesCompat ` and ` DrawableHotspotTouch ` for inflating and interception sequently. Here is sample:
37+
38+ ``` java
39+
40+ public class SampleActivity extends AppCompatActivity {
41+
42+ private FloatingActionButton mActionButton;
43+
44+ @Override
45+ protected void onCreate (Bundle savedInstanceState ) {
46+ super . onCreate(savedInstanceState);
47+ setContentView(R . layout. activity_sample);
48+
49+ mActionButton = (FloatingActionButton ) findViewById(R . id. fab);
50+ mActionButton. setBackgroundDrawable(getDrawable2(R . drawable. fab_background));
51+ mActionButton. setClickable(true );// if we don't set it true, ripple will not be played
52+ mActionButton. setOnTouchListener(
53+ new DrawableHotspotTouch ((LollipopDrawable ) mActionButton. getBackground()));
54+ }
55+
56+ /**
57+ * {@link #getDrawable(int)} is already taken by Android API
58+ * and method is final, so we need to give another name :(
59+ */
60+ public Drawable getDrawable2 (int id ){
61+ return LollipopDrawablesCompat . getDrawable(getResources(), id, getTheme());
62+ }
63+ }
64+
65+ ```
66+
67+ ** Thats it!**
68+
69+ #### a little bit more
70+
71+ you can inflate and create your own ` Drawable ` classes, here is tips & tricks
72+
73+ 1 extend your Drawable from ` LollipopDrawable `
74+ ``` java
75+ public class LayerDrawable extends LollipopDrawable {
76+ ```
77+
78+ 2 implement your own inflation
79+ ```java
80+ public void inflate (Resources r , XmlPullParser parser , AttributeSet attrs , Resources .Theme theme );
81+ ```
82+ 3 Register your `LollipopDrawable `
83+ ```java
84+ static {
85+ LollipopDrawablesCompat . registerDrawable(RippleDrawable . class, " ripple" );
86+ }
87+ ```
88+
89+ 4 inflate it!
90+ ```java
91+ LollipopDrawablesCompat .getDrawable (getResources (), R .drawable.custom_drawable, getTheme ());
92+ ```
3293
3394License
3495--------
@@ -55,3 +116,4 @@ License
55116 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
56117 THE SOFTWARE.
57118
119+
0 commit comments