gpt4 book ai didi

android - 让用户设置浅色或深色主题加上强调色

转载 作者:行者123 更新时间:2023-11-29 23:54:15 25 4
gpt4 key购买 nike

我正在尝试为一个应用程序build设置,我想让它可以自定义,让用户在浅色和深色主题之间做出选择。我已经这样做了https://www.hidroh.com/2015/02/16/support-multiple-themes-android-app/按照本教程。

问题是,我想要另一个选项来选择强调色,就像许多应用程序一样。我怎样才能独立于黑暗/光明实现这一目标?有没有办法避免 Activity 重启?

最佳答案

我使用的方法是,将颜色保存在一个数组中,让用户选择颜色并将所选颜色的索引存储在首选项中。所以当 Activity 加载时读取存储的颜色并相应地设置颜色

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(ContextCompat.getColor(this,colors.getResourceId(chapter_key-1, 0)));
}

main screen where they select the book

package com.**********.app.customViews;

/**
* Created by pakistantechhouse on 18/02/2017.
*/

import android.content.Context;
import android.graphics.Canvas;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.widget.RelativeLayout;

import com.**********.app.R;


public class CRelativeLayout extends RelativeLayout {


public CRelativeLayout(Context context) {
super(context);
if (!isInEditMode()) {
//TODO get your color here from the preferences and apply to the view
this.setBackgroundColor(ContextCompat.getColor(context, R.color.colorPrimary));
}
}

public CRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
if (!isInEditMode()) {
//TODO get your color here from the preferences and apply to the view
this.setBackgroundColor(ContextCompat.getColor(context, R.color.colorPrimary));

}
}

public CRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
if (!isInEditMode()) {
//TODO get your color here from the preferences and apply to the view

this.setBackgroundColor(ContextCompat.getColor(context, R.color.colorPrimary));
}
}

protected void onDraw (Canvas canvas) {
super.onDraw(canvas);

}

}

关于android - 让用户设置浅色或深色主题加上强调色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50545433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com