pref: 设置页面样式卡片化

This commit is contained in:
HuanChengFly 2021-02-12 15:37:43 +08:00
parent 53a1ebdc63
commit 211441139c
8 changed files with 74 additions and 48 deletions

View File

@ -170,12 +170,28 @@ class SettingsFragment : PreferencesFragment() {
initListPreference("dark_theme", "dark")
aboutPreference!!.summary = getString(R.string.tip_about, VersionUtil.getVersionName(attachContext))
refresh()
/*
try {
val preferenceGroupClazz = PreferenceGroup::class.java
val preferencesField = preferenceGroupClazz.getDeclaredField("mPreferences")
preferencesField.isAccessible = true
val preferencesList = preferencesField.get(preferenceScreen) as List<Preference>
attachContext.toastShort("${preferencesList.size}")
} catch (e: Exception) {
e.printStackTrace()
}
*/
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setDivider(ThemeUtils.tintDrawable(ContextCompat.getDrawable(attachContext, R.drawable.drawable_divider_8dp), ThemeUtils.getColorByAttr(attachContext, R.attr.colorDivider)))
setDividerHeight(DisplayUtil.dp2px(attachContext, 8f))
setDivider(
ThemeUtils.tintDrawable(
ContextCompat.getDrawable(attachContext, R.drawable.drawable_divider_8dp),
ThemeUtils.getColorById(attachContext, R.color.default_color_window_background)
)
)
setDividerHeight(0)
}
private fun initSwitchPreference(key: String, defValue: Boolean = false) {

View File

@ -1,20 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<com.huanchengfly.tieba.post.widgets.theme.TintLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:gravity="center_vertical"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:background="?android:attr/selectableItemBackground"
android:layout_marginStart="@dimen/card_margin"
android:layout_marginEnd="@dimen/card_margin"
android:background="@drawable/bg_ripple"
android:clipToPadding="false"
android:focusable="true"
android:baselineAligned="false">
android:baselineAligned="false"
app:backgroundTint="@color/default_color_card">
<include
layout="@layout/layout_preference_icon" />
<include layout="@layout/layout_preference_icon" />
<RelativeLayout
android:layout_width="0dp"
@ -29,7 +31,7 @@
android:layout_height="wrap_content"
android:singleLine="true"
android:textStyle="bold"
app:tintList="@color/text_color_selector"
app:tint="@color/text_color_selector"
android:textAppearance="@style/TextAppearance.MaterialSubhead"
android:ellipsize="marquee"
tools:ignore="PrivateResource" />
@ -42,7 +44,7 @@
android:layout_below="@android:id/title"
android:layout_alignStart="@android:id/title"
android:textSize="14sp"
app:tintList="@color/text_color_secondary_selector"
app:tint="@color/text_color_secondary_selector"
android:maxLines="10"/>
</RelativeLayout>
@ -56,4 +58,4 @@
android:orientation="vertical"
tools:ignore="RtlSymmetry" />
</LinearLayout>
</com.huanchengfly.tieba.post.widgets.theme.TintLinearLayout>

View File

@ -1,18 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<com.huanchengfly.tieba.post.widgets.theme.TintLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:minHeight="15dp"
android:gravity="center_vertical"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:layout_marginStart="@dimen/card_margin"
android:layout_marginEnd="@dimen/card_margin"
android:clipToPadding="false"
android:baselineAligned="false">
android:baselineAligned="false"
android:background="@drawable/bg_bottom_radius_10dp"
app:backgroundTint="@color/default_color_card">
<include
layout="@layout/layout_preference_icon" />
<include layout="@layout/layout_preference_icon" />
<RelativeLayout
android:layout_width="0dp"
@ -25,7 +26,7 @@
android:layout_height="wrap_content"
android:singleLine="true"
android:textStyle="bold"
app:tintList="@color/text_color_selector"
app:tint="@color/text_color_selector"
android:textAppearance="@style/TextAppearance.MaterialSubhead"
android:ellipsize="marquee"
tools:ignore="PrivateResource" />
@ -53,4 +54,4 @@
android:orientation="vertical"
tools:ignore="RtlSymmetry" />
</LinearLayout>
</com.huanchengfly.tieba.post.widgets.theme.TintLinearLayout>

View File

@ -1,14 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<com.huanchengfly.tieba.post.widgets.theme.TintTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingTop="22dp"
android:paddingBottom="12dp"
android:layout_marginStart="?android:attr/listPreferredItemPaddingStart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:padding="12dp"
android:layout_marginStart="@dimen/card_margin"
android:layout_marginEnd="@dimen/card_margin"
android:maxLines="1"
android:textStyle="bold"
android:ellipsize="end"
android:textSize="16sp"
app:tint="@color/default_color_primary"
android:background="@drawable/bg_top_radius_10dp"
app:backgroundTint="@color/default_color_card"
android:id="@android:id/title" />

View File

@ -1,14 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<com.huanchengfly.tieba.post.widgets.theme.TintTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:layout_marginStart="?android:attr/listPreferredItemPaddingStart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:layout_marginStart="@dimen/card_margin"
android:layout_marginEnd="@dimen/card_margin"
android:maxLines="1"
android:textStyle="bold"
android:ellipsize="end"
android:textSize="16sp"
app:tint="@color/default_color_primary"
android:background="@drawable/bg_top_radius_10dp"
app:backgroundTint="@color/default_color_card"
android:id="@android:id/title" />

View File

@ -1,20 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<com.huanchengfly.tieba.post.widgets.theme.TintLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:gravity="center_vertical"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:background="?android:attr/selectableItemBackground"
android:layout_marginStart="@dimen/card_margin"
android:layout_marginEnd="@dimen/card_margin"
android:background="@drawable/bg_ripple"
android:clipToPadding="false"
android:focusable="true"
android:baselineAligned="false">
android:baselineAligned="false"
app:backgroundTint="@color/default_color_card">
<include
layout="@layout/layout_preference_icon" />
<include layout="@layout/layout_preference_icon" />
<RelativeLayout
android:layout_width="0dp"
@ -29,7 +31,7 @@
android:layout_height="wrap_content"
android:singleLine="true"
android:textStyle="bold"
app:tintList="@color/text_color_selector"
app:tint="@color/text_color_selector"
android:textAppearance="@style/TextAppearance.MaterialSubhead"
android:ellipsize="marquee"
android:layout_marginBottom="4dp"
@ -58,4 +60,4 @@
android:orientation="vertical"
tools:ignore="RtlSymmetry" />
</LinearLayout>
</com.huanchengfly.tieba.post.widgets.theme.TintLinearLayout>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<com.huanchengfly.tieba.post.widgets.theme.TintLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
@ -8,14 +8,15 @@
android:gravity="center_vertical"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:background="?android:attr/selectableItemBackground"
android:layout_marginStart="@dimen/card_margin"
android:layout_marginEnd="@dimen/card_margin"
android:background="@drawable/bg_ripple"
android:clipToPadding="false"
android:clipChildren="false"
android:focusable="true"
android:baselineAligned="false">
android:baselineAligned="false"
app:backgroundTint="@color/default_color_card">
<include
layout="@layout/layout_preference_icon" />
<include layout="@layout/layout_preference_icon" />
<LinearLayout
android:layout_width="match_parent"
@ -37,7 +38,7 @@
android:layout_height="wrap_content"
android:singleLine="true"
android:textStyle="bold"
app:tintList="@color/text_color_selector"
app:tint="@color/text_color_selector"
android:textAppearance="@style/TextAppearance.MaterialSubhead"
android:ellipsize="marquee"
tools:ignore="PrivateResource" />
@ -50,7 +51,7 @@
android:layout_below="@android:id/title"
android:layout_alignStart="@android:id/title"
android:textSize="14sp"
app:tintList="@color/text_color_secondary_selector"
app:tint="@color/text_color_secondary_selector"
android:maxLines="10"/>
</RelativeLayout>
@ -93,11 +94,11 @@
android:textAppearance="?android:attr/textAppearanceListItem"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
app:tintList="@color/text_color_secondary_selector"
app:tint="@color/text_color_secondary_selector"
android:scrollbars="none"
tools:ignore="PrivateResource" />
</com.huanchengfly.tieba.post.widgets.UnPressableLinearLayout>
</LinearLayout>
</LinearLayout>
</com.huanchengfly.tieba.post.widgets.theme.TintLinearLayout>

View File

@ -2,7 +2,6 @@
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.preference.PreferenceCategory
android:layout="@layout/layout_preference_category_first"
android:title="@string/title_account">
<ListPreference
android:icon="@drawable/ic_round_account_circle"