我使用这个优秀的库:https://github.com/vikramkakkar/SublimePicker/
我已升级到Android SDK 27.1.0,现在Sublime选择器的背景颜色为灰色而非白色......
这是我原来的风格:
<style name="DateTimePickerDefault" parent="SublimePickerStyleLight">
<item name="colorAccent">@color/theme_accent_3</item>
<item name="colorPrimaryDark">@color/theme_primary</item>
<item name="colorPrimary">@color/icon_theme_primary</item>
<item name="android:textColorPrimary">@color/icon_theme_primary</item>
<item name="android:textColorSecondary">#727272</item>
<item name="android:textColorPrimaryInverse">@android:color/white</item>
<item name="android:textColor">@color/theme_primary</item>
</style>
你有什么想法吗?
答案 0 :(得分:0)
好的,我使用反射过程将背景颜色正确设置为主视图。
public class ExtendSublimePicker extends SublimePicker {
private int mBackgroundColor = Color.WHITE; // By default
public ExtendSublimePicker(Context context) {
super(context);
}
public ExtendSublimePicker(Context context, AttributeSet attrs) {
super(context, attrs);
refreshBackgroundColor();
}
public ExtendSublimePicker(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
refreshBackgroundColor();
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ExtendSublimePicker(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
refreshBackgroundColor();
}
@Override
public void setBackgroundColor(@ColorInt int color) {
mBackgroundColor = color;
refreshBackgroundColor();
}
private void refreshBackgroundColor() {
Field field = getField(getClass(), "llMainContentHolder");
if (field != null) {
try {
View view = (View) field.get(this);
view.setBackgroundColor(mBackgroundColor);
} catch (Exception e) {
}
}
}
private static Field getField(Class<?> cls, String fieldName) {
for (Class<?> c = cls; c != null; c = c.getSuperclass()) {
try {
final Field field = c.getDeclaredField(fieldName);
field.setAccessible(true);
return field;
} catch (final NoSuchFieldException e) {
// Try parent
} catch (Exception e) {
throw new IllegalArgumentException(
"Cannot access field " + cls.getName() + "." + fieldName, e);
}
}
throw new IllegalArgumentException(
"Cannot find field " + cls.getName() + "." + fieldName);
}
}