feat: 添加应用背景图片设置功能
功能特性: 1. BackgroundPreferences 管理背景图片设置(URI、启用状态、透明度) 2. 设置页面新增背景图片设置卡片(开关、选择、透明度、清除) 3. BackgroundHelper 工具类帮助 Fragment 应用背景图片 4. HomeFragment 已集成背景图片显示 设置界面: - 启用/禁用背景图片开关 - 选择图片按钮(从相册选择) - 透明度滑块(5%-100%可调) - 清除背景图片按钮(红色警告按钮) 技术实现: - 使用 SharedPreferences 存储背景图片 URI - Glide 异步加载背景图片 - 支持持久化 URI 权限 - 实时保存所有设置 - HomeFragment 自动应用背景 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6bbd0cb59c
commit
fd96f2c1a2
6 files changed
+534
-6
No files matched your search
@@ -1,12 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
<androidx.core.widget.NestedScrollView
|
||||
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="match_parent"
|
||||
android:padding="16dp"
|
||||
tools:context=".ui.SettingsFragment">
|
||||
android:background="@color/bg_primary"
|
||||
android:fillViewport="true">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/spacing_md"
|
||||
tools:context=".ui.SettingsFragment">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvPlayModeLabel"
|
||||
@@ -109,10 +115,123 @@
|
||||
android:id="@+id/switchChangeOnReturn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginTop="@dimen/spacing_sm"
|
||||
android:layout_marginEnd="@dimen/spacing_md"
|
||||
android:checked="true"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvChangeOnReturnDesc"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
<!-- 背景图片设置卡片 -->
|
||||
<TextView
|
||||
android:id="@+id/tvBackgroundLabel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="应用背景"
|
||||
android:textSize="@dimen/text_size_lg"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/text_primary"
|
||||
android:layout_marginTop="@dimen/spacing_lg"
|
||||
app:layout_constraintTop_toBottomOf="@id/switchChangeOnReturn"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/cardBackground"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/spacing_sm"
|
||||
app:cardElevation="@dimen/card_elevation"
|
||||
app:cardCornerRadius="@dimen/corner_radius_md"
|
||||
app:cardBackgroundColor="@color/bg_card"
|
||||
app:strokeColor="@color/glass_border"
|
||||
app:strokeWidth="@dimen/glass_border_width"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvBackgroundLabel"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/card_padding">
|
||||
|
||||
<!-- 背景开关和选择按钮 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<Switch
|
||||
android:id="@+id/switchBackground"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="启用背景图片"
|
||||
android:textSize="@dimen/text_size_md"
|
||||
android:textColor="@color/text_primary" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btnSelectBackground"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="选择图片"
|
||||
android:textSize="@dimen/text_size_sm"
|
||||
android:layout_marginStart="@dimen/spacing_md"
|
||||
app:icon="@drawable/ic_image"
|
||||
app:iconGravity="textStart"
|
||||
app:cornerRadius="@dimen/corner_radius_sm"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 透明度滑块 -->
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="背景透明度"
|
||||
android:textSize="@dimen/text_size_sm"
|
||||
android:textColor="@color/text_secondary"
|
||||
android:layout_marginTop="@dimen/spacing_md" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekBarBackgroundAlpha"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:max="100"
|
||||
android:min="5"
|
||||
android:progress="30"
|
||||
android:layout_marginTop="@dimen/spacing_sm" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvBackgroundAlpha"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="30%"
|
||||
android:textSize="@dimen/text_size_sm"
|
||||
android:textColor="@color/text_hint"
|
||||
android:layout_marginTop="@dimen/spacing_xs"
|
||||
android:layout_gravity="end" />
|
||||
|
||||
<!-- 清除按钮 -->
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btnClearBackground"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="清除背景图片"
|
||||
android:textSize="@dimen/text_size_sm"
|
||||
android:layout_marginTop="@dimen/spacing_md"
|
||||
app:icon="@drawable/ic_delete"
|
||||
app:iconGravity="textStart"
|
||||
app:cornerRadius="@dimen/corner_radius_sm"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
android:textColor="@color/color_error"
|
||||
app:iconTint="@color/color_error"
|
||||
app:strokeColor="@color/color_error" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<!-- 背景图片 -->
|
||||
<ImageView
|
||||
android:id="@+id/ivBackgroundImage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop"
|
||||
android:alpha="0.3"
|
||||
android:contentDescription="应用背景图片" />
|
||||
|
||||
<!-- 暗色遮罩层(确保内容可读性) -->
|
||||
<View
|
||||
android:id="@+id/viewDimOverlay"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#AA000000" />
|
||||
|
||||
<!-- 内容容器 -->
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:id="@+id/contentContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true">
|
||||
|
||||
<!-- 原始内容将在这里动态添加 -->
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
</FrameLayout>
|
||||
Reference in new issue
Block a user