feat: 优化代码

pull/198/head
kunfei 5 years ago
parent a44d2da989
commit 66777624cc
  1. 8
      app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt
  2. 12
      app/src/main/res/drawable/bg_prefs_color.xml

@ -1,7 +1,6 @@
package io.legado.app.ui.widget.prefs
import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.view.LayoutInflater
@ -12,10 +11,7 @@ import android.widget.TextView
import androidx.core.view.isVisible
import androidx.preference.PreferenceViewHolder
import io.legado.app.R
import io.legado.app.lib.theme.Selector
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.backgroundColor
import io.legado.app.utils.getCompatColor
import org.jetbrains.anko.layoutInflater
import kotlin.math.roundToInt
@ -41,10 +37,6 @@ class Preference(context: Context, attrs: AttributeSet) :
weightHeight: Int = 0
): T? {
if (it == null) return null
it.itemView.background = Selector.drawableBuild()
.setDefaultDrawable(ColorDrawable(context.backgroundColor))
.setPressedDrawable(ColorDrawable(context.getCompatColor(R.color.btn_bg_press)))
.create()
val view = it.findViewById(R.id.preference_title)
if (view is TextView) {
view.text = title

@ -1,10 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/btn_bg_press">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/background_prefs" />
<corners android:radius="0dp" />
</shape>
</item>
</ripple>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/btn_bg_press" />
</selector>
Loading…
Cancel
Save