优化强调色和文字颜色一样是文字颜色的显示

This commit is contained in:
kunfei
2022-05-02 10:09:51 +08:00
parent 0ddca512b5
commit c3dde6e8e2
3 changed files with 15 additions and 16 deletions
@@ -23,7 +23,6 @@ class AccentBgTextView @JvmOverloads constructor(
radius = typedArray.getDimensionPixelOffset(R.styleable.AccentBgTextView_radius, radius) radius = typedArray.getDimensionPixelOffset(R.styleable.AccentBgTextView_radius, radius)
typedArray.recycle() typedArray.recycle()
upBackground() upBackground()
setTextColor(Color.WHITE)
} }
fun setRadius(radius: Int) { fun setRadius(radius: Int) {
@@ -32,18 +31,22 @@ class AccentBgTextView @JvmOverloads constructor(
} }
private fun upBackground() { private fun upBackground() {
background = if (isInEditMode) { val accentColor = if (isInEditMode) {
Selector.shapeBuild() context.getCompatColor(R.color.accent)
.setCornerRadius(radius)
.setDefaultBgColor(context.getCompatColor(R.color.accent))
.setPressedBgColor(ColorUtils.darkenColor(context.getCompatColor(R.color.accent)))
.create()
} else { } else {
Selector.shapeBuild() ThemeStore.accentColor(context)
.setCornerRadius(radius)
.setDefaultBgColor(ThemeStore.accentColor(context))
.setPressedBgColor(ColorUtils.darkenColor(ThemeStore.accentColor(context)))
.create()
} }
background = Selector.shapeBuild()
.setCornerRadius(radius)
.setDefaultBgColor(accentColor)
.setPressedBgColor(ColorUtils.darkenColor(accentColor))
.create()
setTextColor(
if (ColorUtils.isColorLight(accentColor)) {
Color.BLACK
} else {
Color.WHITE
}
)
} }
} }
@@ -402,11 +402,9 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:background="@drawable/selector_btn_accent_bg"
android:gravity="center" android:gravity="center"
android:includeFontPadding="false" android:includeFontPadding="false"
android:text="@string/reading" android:text="@string/reading"
android:textColor="@color/tv_text_button_nor"
android:textSize="15sp" /> android:textSize="15sp" />
</LinearLayout> </LinearLayout>
@@ -383,11 +383,9 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:background="@drawable/selector_btn_accent_bg"
android:gravity="center" android:gravity="center"
android:includeFontPadding="false" android:includeFontPadding="false"
android:text="@string/reading" android:text="@string/reading"
android:textColor="@color/tv_text_button_nor"
android:textSize="15sp" /> android:textSize="15sp" />
</LinearLayout> </LinearLayout>