Skip to content

Commit ed1f5e1

Browse files
author
Alien
committed
support ripple and foreground
1 parent ee6540a commit ed1f5e1

29 files changed

+577
-119
lines changed

README.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ code snippet:
1919

2020
```xml
2121
<com.android.base.ui.shape.ShapeableTextView
22-
style="@style/StyleShapeView"
23-
android:layout_width="match_parent"
24-
android:layout_height="70dp"
25-
android:layout_margin="10dp"
26-
android:clickable="true"
27-
android:gravity="center"
28-
android:padding="2dp"
29-
android:text="Click me!"
30-
android:textColor="@color/color_state_test1"
31-
android:textStyle="bold"
32-
app:msd_backgroundColor="@color/color_state_test2"
33-
app:msd_strokeColor="@color/color_state_test1"
34-
app:msd_strokeWidth="4dp"
35-
app:shapeAppearance="@style/ShapeAppearance.Hexagon" />
22+
style="@style/StyleShapeView"
23+
android:layout_width="match_parent"
24+
android:layout_height="70dp"
25+
android:layout_margin="10dp"
26+
android:clickable="true"
27+
android:gravity="center"
28+
android:padding="2dp"
29+
android:text="Click me!"
30+
android:textColor="@color/color_state_test1"
31+
android:textStyle="bold"
32+
app:msd_backgroundColor="@color/color_state_test2"
33+
app:msd_strokeColor="@color/color_state_test1"
34+
app:msd_strokeWidth="4dp"
35+
app:shapeAppearance="@style/ShapeAppearance.Hexagon" />
3636
```
3737

3838
## 2 Lib DrawableView
@@ -46,30 +46,30 @@ code snippet:
4646

4747
```xml
4848
<com.android.base.ui.drawable.DTextView
49-
android:layout_width="150dp"
50-
android:layout_height="150dp"
51-
android:layout_margin="5dp"
52-
android:gravity="center"
53-
android:text="Ztiany"
54-
android:textColor="@color/white"
55-
android:textStyle="bold"
56-
app:cdv_drawable_type="gradient"
57-
app:cgd_shape="rectangle"
58-
app:cgd_shape_corner_style="@style/CornerAppearance.Rounded10"
59-
app:cgd_shape_solid="@color/colorPrimary" />
49+
android:layout_width="150dp"
50+
android:layout_height="150dp"
51+
android:layout_margin="5dp"
52+
android:gravity="center"
53+
android:text="Ztiany"
54+
android:textColor="@color/white"
55+
android:textStyle="bold"
56+
app:cdv_drawable_type="gradient"
57+
app:cgd_shape="rectangle"
58+
app:cgd_shape_corner_style="@style/CornerAppearance.Rounded10"
59+
app:cgd_shape_solid="@color/colorPrimary" />
6060

6161
<com.android.base.ui.drawable.DTextView
62-
android:layout_width="150dp"
63-
android:layout_height="150dp"
64-
android:layout_margin="5dp"
65-
android:gravity="center"
66-
android:text="Ztiany"
67-
android:textColor="@color/white"
68-
android:textStyle="bold"
69-
app:cdv_drawable_type="gradient"
70-
app:cgd_shape="rectangle"
71-
app:cgd_shape_corner_style="@style/StyleGradientDrawableView_Round_TL20"
72-
app:cgd_shape_solid="@color/colorPrimary" />
62+
android:layout_width="150dp"
63+
android:layout_height="150dp"
64+
android:layout_margin="5dp"
65+
android:gravity="center"
66+
android:text="Ztiany"
67+
android:textColor="@color/white"
68+
android:textStyle="bold"
69+
app:cdv_drawable_type="gradient"
70+
app:cgd_shape="rectangle"
71+
app:cgd_shape_corner_style="@style/StyleGradientDrawableView_Round_TL20"
72+
app:cgd_shape_solid="@color/colorPrimary" />
7373
```
7474

7575
Acknowledgment: The core code of Lib DrawableView is copied from [又一个减少冗余 Drawable 资源的解决方案](https://mp.weixin.qq.com/s/qxMoI7UTw3WtiRR6oIDGKA)

app/src/main/java/me/ztiany/drawable/view/example/ShapeViewActivity.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package me.ztiany.drawable.view.example
22

3+
import android.content.res.ColorStateList
4+
import android.graphics.Color
35
import android.graphics.Paint
6+
import android.graphics.drawable.RippleDrawable
47
import android.os.Bundle
58
import android.view.View
69
import android.widget.TextView
@@ -98,6 +101,10 @@ class ShapeViewActivity : AppCompatActivity() {
98101
}
99102
background = drawable
100103
}
104+
105+
findViewById<TextView>(R.id.ripple_tv_01).apply {
106+
background = RippleDrawable(ColorStateList.valueOf(Color.RED), null, null)
107+
}
101108
}
102109

103110
private fun researchHowItWorkByCode() {
1.71 KB
Loading

app/src/main/res/drawable/ripple1.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:color="#FFFF0000">
4+
<item
5+
android:id="@android:id/mask"
6+
android:drawable="@android:color/white" />
7+
</ripple>

app/src/main/res/drawable/ripple2.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:color="#FFFF0000">
4+
</ripple>

app/src/main/res/layout/activity_drawable_view.xml

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,92 @@
346346
android:layout_height="150dp"
347347
android:layout_margin="5dp"
348348
android:clickable="true"
349-
app:cdv_ripple_appearance="@style/CodeRippleDrawable_WithSelector">
349+
app:cdv_ripple_appearance="@style/CodeRippleDrawable_WithSelector0">
350+
351+
<TextView
352+
android:layout_width="wrap_content"
353+
android:layout_height="wrap_content"
354+
android:layout_gravity="center"
355+
android:text="Click me"
356+
android:textColor="@color/red" />
357+
358+
</com.android.base.ui.drawable.DFrameLayout>
359+
360+
<com.android.base.ui.drawable.DFrameLayout
361+
android:layout_width="150dp"
362+
android:layout_height="150dp"
363+
android:layout_margin="5dp"
364+
android:clickable="true"
365+
app:cdv_clip_to_outline="false"
366+
app:cdv_ripple_appearance="@style/CodeRippleDrawable_WithMaskSelector1">
367+
368+
<TextView
369+
android:layout_width="wrap_content"
370+
android:layout_height="wrap_content"
371+
android:layout_gravity="center"
372+
android:text="Click me"
373+
android:textColor="@color/red" />
374+
375+
</com.android.base.ui.drawable.DFrameLayout>
376+
377+
<com.android.base.ui.drawable.DFrameLayout
378+
android:layout_width="150dp"
379+
android:layout_height="150dp"
380+
android:layout_margin="5dp"
381+
android:clickable="true"
382+
app:cdv_clip_to_outline="false"
383+
app:cdv_ripple_appearance="@style/CodeRippleDrawable_WithMaskSelector2">
384+
385+
<TextView
386+
android:layout_width="wrap_content"
387+
android:layout_height="wrap_content"
388+
android:layout_gravity="center"
389+
android:text="Click me"
390+
android:textColor="@color/red" />
391+
392+
</com.android.base.ui.drawable.DFrameLayout>
393+
394+
<com.android.base.ui.drawable.DFrameLayout
395+
android:layout_width="150dp"
396+
android:layout_height="150dp"
397+
android:layout_margin="5dp"
398+
android:clickable="true"
399+
app:cdv_clip_to_outline="false"
400+
app:cdv_ripple_appearance="@style/CodeRippleDrawable_WithMaskSelector3">
401+
402+
<TextView
403+
android:layout_width="wrap_content"
404+
android:layout_height="wrap_content"
405+
android:layout_gravity="center"
406+
android:text="Click me"
407+
android:textColor="@color/red" />
408+
409+
</com.android.base.ui.drawable.DFrameLayout>
410+
411+
<com.android.base.ui.drawable.DFrameLayout
412+
android:layout_width="150dp"
413+
android:layout_height="150dp"
414+
android:layout_margin="5dp"
415+
android:clickable="true"
416+
app:cdv_clip_to_outline="false"
417+
app:cdv_foreground_ripple_appearance="@style/CodeRippleDrawable_WithMaskSelector3">
418+
419+
<TextView
420+
android:layout_width="wrap_content"
421+
android:layout_height="wrap_content"
422+
android:layout_gravity="center"
423+
android:text="Click me"
424+
android:textColor="@color/red" />
425+
426+
</com.android.base.ui.drawable.DFrameLayout>
427+
428+
<com.android.base.ui.drawable.DFrameLayout
429+
android:layout_width="150dp"
430+
android:layout_height="150dp"
431+
android:layout_margin="5dp"
432+
android:clickable="true"
433+
app:cdv_clip_to_outline="false"
434+
app:cdv_foreground_selector_appearance="@style/CodeSelectorDrawable_TranslucentSolid_1">
350435

351436
<TextView
352437
android:layout_width="wrap_content"

0 commit comments

Comments
 (0)