Skip to content

Commit

Permalink
针对6.0+的系统做了水波纹的兼容
Browse files Browse the repository at this point in the history
  • Loading branch information
Kale committed Oct 11, 2018
1 parent 484f339 commit b361711
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/src/main/res/layout/image_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

app:pressedStrokeColor="#259b24"
app:pressedStrokeWidth="8dp"

app:ripple="true"
/>

<LinearLayout
Expand Down
11 changes: 9 additions & 2 deletions lib/src/main/java/kale/injection/SelectorInjection.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,15 @@ private void setSelectorDrawableToView() {

ripple.setColor(ColorStateList.valueOf(pressed.color));
ripple.setDrawableByLayerId(android.R.id.mask, normal.drawable); // 这里用的normal时的drawable做边界
ripple.setDrawableByLayerId(android.R.id.content, selector);
view.setBackground(ripple);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
view.setForeground(ripple);
view.setBackground(selector);
} else {
ripple.setDrawableByLayerId(android.R.id.content, selector);
view.setBackground(ripple);
}

return;
}

Expand Down
10 changes: 10 additions & 0 deletions lib/src/main/res/drawable-v23/si_ripple.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?><!-- si = selector injection 用来避开资源冲突 -->
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#ff0000"
>
<item
android:id="@android:id/mask"
android:drawable="@color/default_color"
/>

</ripple>

0 comments on commit b361711

Please sign in to comment.