当前位置:网站首页>[launch] modify the app theme according to the wallpaper. It really comes
[launch] modify the app theme according to the wallpaper. It really comes
2022-06-09 22:16:00 【InfoQ】
1、 Preface
2、 effect

3、 Introduce
3.1、 What is? Material You
Material You3.2、 What is dynamic color
Dynamic Color3.3、 What is the principle of dynamic color
- First , Extract a source color from the user's wallpaper , And calculate 5 Key colors in , such as primary、Secondary、Tertiary etc. .
- then , Convert each key color to 13 A palette of colors , And each tone will generate a corresponding light color 、 Dark scheme .
- Last , Through the system Token The color scheme and... Will be extracted from the wallpaper App Theme Connect , stay DynamicColorsActivityLifecycleCallbacks Determine whether it needs to be overwritten .
4、 Realization
4.1、 Migrate to M3
4.1.1、 to update Gradle rely on
material1.5.0implementation 'com.google.android.material:material:1.5.0'
4.1.2、 Revised version
compileSdkVersiontargetSdkVersion31android {
compileSdkVersion 31
defaultConfig {
applicationId "com.yechaoa.materialdesign"
minSdkVersion 23
targetSdkVersion 31
...
}
...
}
Android12android:exported4.1.3、 modify App The theme
Theme.AppCompat.*Theme.MaterialComponents.*Theme.Material3.* <style name="AppTheme" parent="Theme.Material3.DayNight.NoActionBar">
</style>
4.2、 Add dynamic colors
4.2.1、 Apply dynamic colors
class App: Application() {
override fun onCreate() {
super.onCreate()
// apply dynamic color
DynamicColors.applyToActivitiesIfAvailable(this)
}
}
Application- applyToActivitiesIfAvailable(@NonNull Application application, @StyleRes int theme) The second parameter represents the user-defined coverage system theme
- applyIfAvailable(@NonNull Activity activity) Or some Activity
- applyIfAvailable(@NonNull Activity activity, @StyleRes int theme) Or just one Activity Cover
- wait
4.2.2、 Sign up to manifest
android:name <application
android:name=".App"
...
android:theme="@style/AppTheme">
...
</application>
4.2.3、 Use dynamic colors
Hard encoding android:background="@color/colorPrimary"
Dynamic access android:background="?attr/colorPrimary"
4.3、Material Theme Builder
4.2.1Material Theme Builder4.3.1、 Wallpaper Preview

add your wallpaper4.3.2、 Customize Theme
CUSTOM

EXPORT
FlutterWeb
4.3.3、Theme Cover
overlay <style name="AppTheme.Overlay" parent="ThemeOverlay.Material3.DynamicColors.DayNight">
<item name="colorPrimary">@color/overlay_colorPrimary</item>
...
</style>
DynamicColors.applyToActivitiesIfAvailable(this, R.style.AppTheme.Overlay)
4.4、 Whether dynamic colors are supported
@SuppressLint("DefaultLocale")
@ChecksSdkIntAtLeast(api = VERSION_CODES.S)
public static boolean isDynamicColorAvailable() {
if (VERSION.SDK_INT < VERSION_CODES.S) {
return false;
}
DeviceSupportCondition deviceSupportCondition =
DYNAMIC_COLOR_SUPPORTED_MANUFACTURERS.get(Build.MANUFACTURER.toLowerCase());
if (deviceSupportCondition == null) {
deviceSupportCondition = DYNAMIC_COLOR_SUPPORTED_BRANDS.get(Build.BRAND.toLowerCase());
}
return deviceSupportCondition != null && deviceSupportCondition.isSupported();
}
deviceMap.put("oppo", DEFAULT_DEVICE_SUPPORT_CONDITION);
deviceMap.put("realme", DEFAULT_DEVICE_SUPPORT_CONDITION);
deviceMap.put("oneplus", DEFAULT_DEVICE_SUPPORT_CONDITION);
deviceMap.put("vivo", DEFAULT_DEVICE_SUPPORT_CONDITION);
deviceMap.put("xiaomi", DEFAULT_DEVICE_SUPPORT_CONDITION);
deviceMap.put("motorola", DEFAULT_DEVICE_SUPPORT_CONDITION);
deviceMap.put("itel", DEFAULT_DEVICE_SUPPORT_CONDITION);
deviceMap.put("tecno mobile limited", DEFAULT_DEVICE_SUPPORT_CONDITION);
deviceMap.put("infinix mobility limited", DEFAULT_DEVICE_SUPPORT_CONDITION);
deviceMap.put("hmd global", DEFAULT_DEVICE_SUPPORT_CONDITION);
deviceMap.put("sharp", DEFAULT_DEVICE_SUPPORT_CONDITION);
deviceMap.put("sony", DEFAULT_DEVICE_SUPPORT_CONDITION);
deviceMap.put("tcl", DEFAULT_DEVICE_SUPPORT_CONDITION);
deviceMap.put("lenovo", DEFAULT_DEVICE_SUPPORT_CONDITION);
deviceMap.put("lge", DEFAULT_DEVICE_SUPPORT_CONDITION);
deviceMap.put("google", DEFAULT_DEVICE_SUPPORT_CONDITION);
deviceMap.put("robolectric", DEFAULT_DEVICE_SUPPORT_CONDITION);
deviceMap.put("samsung", SAMSUNG_DEVICE_SUPPORT_CONDITION);
5、 summary
6、Github
7、 file
- Migrating to Material Design 3
- Material Design 3
- Material Theme Builder
- DynamicColors
8、 Last
边栏推荐
- After several twists and turns, how long can the TSDB C-bit of incluxdb last?
- node.js 连接sqlserver封装mssql
- 邦纳雷达传感器Q120RAQ-CN-AF19719
- Intelligent prevention and control of safety production risk at construction site in flood season
- 这本书押中了2022北京高考作文题
- Basic query statement
- 2022安全生產月活動啟動安全生產與疫情防控兩手抓
- Leetcode:547. Circle of friends
- ST-Link V2 下载出现:internal command error&Error: Flash Download failed - Target DLL has been cancelled
- Wechat applet obtains provincial and urban information according to longitude and latitude
猜你喜欢

RCNN series summary

SPIDER Pi Intelligent Vision hexapode Robot VNC Connect Robot 0603

The application of prototype object strengthens the function of array object 0526

86. (leaflet house) leaflet military plotting - collection of linear arrows

Database daily question - day 7: customers with the most orders

Digital engineering construction enterprises carry out "safety production month" activities in this way

How to implement a custom rich text editor label

Huawei cloud zero code development image compression tool

ST-Link V2 下载出现:internal command error&Error: Flash Download failed - Target DLL has been cancelled

Alternative scheme for electric energy acquisition terminal of Langer ffc3 watt hour meter (DLMS infrared photoelectric collector)
随机推荐
基础查询语句
FPN-Feature Pyramid Network
Spider PI intelligent vision hexapod robot color tracking face recognition 0604
An RS485 serial interface current sensor snap on type mutual inductor supports Modbus communication protocol
函数对象(仿函数)
chez scheme 环境搭建
Meanings of combined reactive power 1 and combined reactive power 2 in gateway meter parameters of power plant enterprises -- meter reading and data acquisition
什么是“大安全”产业?数字化赋能大安全产业发展
node. JS connecting sqlserver encapsulating MSSQL
Introduction to startup of spider PI intelligent vision hexapod robot 0602
华为设备配置Hub and Spoke
Unity get the content information of XML file
稍微复杂的查询
Some Oracle DDL operations
How to implement a custom rich text editor label
Spider PI intelligent vision hexapod robot VNC connecting robot 0603
veracrypt 创建文件型加密卷
线程池的学习记录
C语言试题162之圆周率π
Actions before purchasing memory modules