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

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