Skip to content

Commit 86f001d

Browse files
committed
实现setPrimaryColors
1 parent 7a6eb2b commit 86f001d

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

android/src/main/java/com/lmy/header/AnyHeader.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lmy.header;
22

33
import android.content.Context;
4+
import android.graphics.drawable.BitmapDrawable;
45
import android.support.annotation.ColorInt;
56
import android.support.annotation.NonNull;
67
import android.view.View;
@@ -20,6 +21,7 @@
2021
public class AnyHeader extends ReactViewGroup implements RefreshHeader {
2122
private RefreshKernel mRefreshKernel;
2223
private int mBackgroundColor;
24+
private Integer mPrimaryColor;
2325
private SpinnerStyle mSpinnerStyle = SpinnerStyle.Translate;
2426

2527
public AnyHeader(Context context) {
@@ -47,15 +49,24 @@ public SpinnerStyle getSpinnerStyle() {
4749
return this.mSpinnerStyle;//指定为平移,不能null
4850
}
4951

52+
/**
53+
* 设置主题色
54+
* @param colors
55+
*/
5056
@Override
5157
public void setPrimaryColors(int... colors) {
52-
58+
if(colors.length>0) {
59+
if (!(getBackground() instanceof BitmapDrawable) && mPrimaryColor == null) {
60+
setPrimaryColor(colors[0]);
61+
mPrimaryColor = null;
62+
}
63+
}
5364
}
5465

5566
public AnyHeader setPrimaryColor(@ColorInt int primaryColor) {
56-
mBackgroundColor = primaryColor;
67+
mBackgroundColor = mPrimaryColor =primaryColor;
5768
if (mRefreshKernel != null) {
58-
mRefreshKernel.requestDrawBackgroundForHeader(primaryColor);
69+
mRefreshKernel.requestDrawBackgroundForHeader(mPrimaryColor);
5970
}
6071
return this;
6172
}

0 commit comments

Comments
 (0)