Android实战:APP换肤功能,并自动适配手机深色模式

本文介绍了在Android应用中实现换肤功能并自动适配手机深色模式的方法。通过QDSkinManager在自定义Application中加载并配置,然后在Activity中注册和取消注册以实现换肤。文章详细展示了关键代码实现,包括在XML布局文件中使用QMUI提供的换肤属性。
摘要由CSDN通过智能技术生成

private QDPreferenceManager(Context context) {

sPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());

}

public static final QDPreferenceManager getInstance(Context context) {

if (sQDPreferenceManager == null) {

sQDPreferenceManager = new QDPreferenceManager(context);

}

return sQDPreferenceManager;

}

public void setAppVersionCode(int code) {

final SharedPreferences.Editor editor = sPreferences.edit();

editor.putInt(APP_VERSION_CODE, code);

editor.apply();

}

public void setSkinIndex(int index) {

SharedPreferences.Editor editor = sPreferences.edit();

editor.putInt(APP_SKIN_INDEX, index);

editor.apply();

}

public int getSkinIndex() {

return sPreferences.getInt(APP_SKIN_INDEX, QDSkinManager.SKIN_DEFAULT);

}

}

[](()1.5、APP加载QDSkinManager并适配深色模式

该工作仅需做一次即可,建议:自定义Application,实现该功能。

src/main/java/com/qxc/testandroid/QDApplication.java:

package com.qxc.testandroid;

import android.annotation.SuppressLint;

import android.app.Application;

import android.content.Context;

import android.content.res.Configuration;

import androidx.annotation.NonNull;

public class QDApplication extends Application {

@SuppressLint(“StaticFieldLeak”)

private static Context contex

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值