garretyoder / colorful Goto Github PK
View Code? Open in Web Editor NEWAndroid runtime theme library
License: Apache License 2.0
Android runtime theme library
License: Apache License 2.0
I think adding .gitignore
files is a good idea
I have added Colorful library into my app and ActionMode is broken now. Action toolbar appears above the toolbar. Looks like Colorful style doesn't have or ignore my windowActionModeOverlay
.
Library initialized as:
CustomThemeColor defaultTheme = new CustomThemeColor(
this,
R.style.my_default_primary_color,
R.style.my_default_rimary_dark_color,
R.color.colorPrimary,
R.color.colorPrimary
);
Defaults themeDefaults = new Defaults(
defaultTheme,
defaultTheme,
false,
false,
R.style.AppTheme
);
initColorful(this, themeDefaults);
Activity extends CAppCompatActivity
. But startSupportActionMode
leads to this:
Do you know how to fix this?
I think adding the gradle wrapper is a good idea
I am using Colorful and want to allow users choose themes from settings. Added ColorClickerPreference
to my preferences file and getting crash when trying to open settings now.
Log
FATAL EXCEPTION: main
Process: com.itemstudio.castro, PID: 22833
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.itemstudio.castro/com.itemstudio.castro.settings.SettingsActivity}: java.lang.ClassCastException: org.polaric.colorful.ColorPickerPreference cannot be cast to android.preference.Preference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2680)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2741)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6176)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
Caused by: java.lang.ClassCastException: org.polaric.colorful.ColorPickerPreference cannot be cast to android.preference.Preference
at android.preference.PreferenceGroup.addItemFromInflater(PreferenceGroup.java:104)
at android.preference.GenericInflater.rInflate(GenericInflater.java:490)
at android.preference.GenericInflater.inflate(GenericInflater.java:327)
at android.preference.GenericInflater.inflate(GenericInflater.java:264)
at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:280)
at android.preference.PreferenceFragment.addPreferencesFromResource(PreferenceFragment.java:326)
at com.itemstudio.castro.settings.SettingsFragment.onCreate(SettingsFragment.java:23)
at android.app.Fragment.performCreate(Fragment.java:2336)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:949)
at android.app.BackStackRecord.setLastIn(BackStackRecord.java:861)
at android.app.BackStackRecord.calculateFragments(BackStackRecord.java:901)
at android.app.BackStackRecord.run(BackStackRecord.java:728)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1578)
at android.app.FragmentController.execPendingActions(FragmentController.java:371)
at android.app.Activity.performStart(Activity.java:6695)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2643)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2741)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6176)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
@garretyoder If use THEME_MATERIAL
or THEME_MATERIAL_COMPONETS
, the following error will appear. What did i do wrong?
Code
ColorfulKt.Colorful().apply(this, true, BaseTheme.THEME_MATERIAL_COMPONETS);
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
Log
AppCompatDelegate: Failed to instantiate custom view inflater android.support.design.theme.MaterialComponentsViewInflater . Falling back to default.
java.lang.ClassNotFoundException: Invalid name: android.support.design.theme.MaterialComponentsViewInflater
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:453)
at java.lang.Class.forName(Class.java:378)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1014)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1092)
ThemeColor.WHITE
, how to set primary or accent color to white or black color?After trying this quite a while now, I can't get it working after restarting my app.
What I do:
Init colorful with the values from my own preferences (had some theming already before I tried your library):
fun init(app: Application) {
var primaryColor = when (AppPrefs.themeColor) {
"0" -> ThemeColor.GREEN
"1" -> ThemeColor.RED
"2" -> ThemeColor.PINK
"3" -> ThemeColor.BLUE
else -> ThemeColor.GREEN
}
var accentColor = when (AppPrefs.themeColor) {
"0" -> ThemeColor.ORANGE
"1" -> ThemeColor.BLUE
"2" -> ThemeColor.BLUE
"3" -> ThemeColor.RED
else -> ThemeColor.GREEN
}
val defaults = Defaults(
primaryColor = primaryColor,
accentColor = accentColor,
useDarkTheme = darkTheme(),
translucent = false,
customTheme = baseActivityTheme()
)
initColorful(app, defaults)
}
Update colorful whenever my preferences change:
fun update(context: Context) {
var primaryColor = when (themeColor()) {
Color.Green -> ThemeColor.GREEN
Color.Red -> ThemeColor.RED
Color.Rosa -> ThemeColor.PINK
Color.Blue -> ThemeColor.BLUE
}
var accentColor = when (themeColor()) {
Color.Green -> ThemeColor.ORANGE
Color.Red -> ThemeColor.BLUE
Color.Rosa -> ThemeColor.BLUE
Color.Blue -> ThemeColor.RED
}
Colorful().edit()
.setPrimaryColor(primaryColor)
.setAccentColor(accentColor)
.setDarkTheme(darkTheme())
.setTranslucent(false)
.setCustomThemeOverride(baseActivityTheme())
.apply(context)
}
Observations
update
function, all my activities are themed correctly until I kill my app and restart itAny ideas why?
Resource IDs are not 100% guaranteed to never change and this could potentially cause problems. We should be loading style resources internally by string name over res id int.
What does "dynamically" mean?
Is an Activity restart required?
Should be added to the readme.
In a custom activity I have to call Colorful().apply(this, override = true, appcompat = false)
in onCreate
. I'm missing the delegate for the onResume
call like the example here has it: https://github.com/garretyoder/Colorful/blob/master/library/src/main/java/io/multimoon/colorful/CAppCompatActivity.kt
This is necessary in a custom activity as well, isn't it?
I have forced to load an style by calling:
Colorful().edit()
.setPrimaryColor(ThemeColor.RED)
.setAccentColor(ThemeColor.BLUE)
.setDarkTheme(false)
.setTranslucent(false)
.setCustomThemeOverride(R.style.AppThemeDark)
.apply(activity!!) { activity!!.recreate() }
And set a textAppearance in my style:
But nothing seems to take a change in text color of my textviews or buttons.
Is there any guide to how to customize widgets?
Is is possible to use this without having to use kotlin? just Java
Kindly share some sample code on the README.
I tried some Kotlin decompiling but it didn't work
Can we have the accent colors change immediately after apply? That is without leaving the current screen? I tried to trigger a color change from color picker dialog but it doesn't do anything to the current screen
I followed all the step ofI implement for current version to my kotlin project
implementation 'com.github.garretyoder:Colorful:2.3.4'
But always failed to build the library.
Colorful has error when start strict mode
override fun onCreate() {
if (BuildConfig.DEBUG) {
setStrictMode()
}
super.onCreate()
}
private fun setStrictMode() {
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork() // or .detectAll() for all detectable problems
.penaltyLog()
.build())
StrictMode.setVmPolicy(StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.penaltyDeath()
.build())
}
How to set custom color codes for Accent and Primary colors, such as#FFFFFF
?
If not support now, can you add a method to set the color code for Primary and Accent? This is useful, thanks.
this has no appbar when mainActivity extends CActivity
Instead of always loading the saved preferences, could you add support for a dynamic config?
E.g. I would like to pass in a custom Defaults
to Colorful().apply(this, override = true, appcompat = false)
which should be used instead of the saved one if present
Hi,
The library works well, but the ability to customise the colors would be great.
Is it something you'll add to the library ?
Hello,
I am encountering an issue when running the library on API 19 (Android 4.1)...
R seems to not be created correctly on compile.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: dev.defvs.chatterz, PID: 2735
java.lang.NoClassDefFoundError: io.multimoon.colorful.R$style
at io.multimoon.colorful.ThemeColor.<clinit>(ThemeColor.kt:60)
at dev.defvs.chatterz.MainApplication.onCreate(MainApplication.kt:13)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
I don't think CActivity
sounds much meaningful. Could we rename it to ColorfulActivity
?
There should be a conflict between your library and another one. When adding Colorful it shows a Gradle problem that say:
Error:(723) Attribute "dialogTitle" already defined with incompatible format.
As soon as I delete the dependency the error disappears. I hope you can fix this.
Broken by commit 1b8f015
Issue: The styles primary7
and primary8
are exactly the same, but primary8
should be teal instead of cyan. The same applies for accent8
. The ordinal value of ThemeColor.TEAL is 8.
@garretyoder I want to use "customTheme", because only in this way can I change textColorPrimary
color, but now primaryColor
and accentColor
are not used, this may be misunderstood, but these two values are non-null.
val defaults:Defaults = Defaults(
primaryColor = ThemeColor.GREEN,
accentColor = ThemeColor.BLUE,
useDarkTheme = false,
translucent = false,
customTheme = R.style.AppTheme)
initColorful(this, defaults)
This is the best theming library i have found so far!
I hope you add support for Mike Penz's Material Drawer Library (also MaterialDrawerKt which is based on the original Library)
I tried using the Colorful's
.setCustomThemeOverride(R.style.AppTheme)
with the theme attributes specified here
but it doesnt seem to work or maybe I'm doing it wrong?
Hi, thankyou your library, I'm useing 2.0 version now, I want know what is the use of override
and appcompat
?
ColorfulKt.Colorful().apply(activity, override, appcompat);
When should I use true and when should I use false?
make the public class ColorPickerDialog extends android.support.v7.app.AlertDialog is better than just extends Dialog ,in this way ,There will be no white blank title bar
@garretyoder Request to add DARK_GREY
, because use "DARK_GREY" color in dark theme is best choose, thanks.
I use Colorful.config(this) .translucent(true) .apply();
to make my Drawerlayout's content translucent, but to find it makes it too dark, which didn't happen if I use custom Theme instead of this library.
FIY, my original theme contains these properties:
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
I tries build a release build of my app and app crashed while start:
Fatal Exception: java.lang.AssertionError: impossible
at java.lang.Enum$1.create(Enum.java:272)
at java.lang.Enum$1.create(Enum.java:263)
at libcore.util.BasicLruCache.get(BasicLruCache.java:58)
at java.lang.Enum.getSharedConstants(Enum.java:289)
at java.lang.Enum.valueOf(Enum.java:244)
at io.multimoon.colorful.ThemeColor.valueOf(Unknown Source:2)
at io.multimoon.colorful.ThemeColorInterface$Companion.parse(ThemeColor.kt:18)
at io.multimoon.colorful.ColorfulKt.initColorful(Colorful.kt:29)
at com.noodoe.nexlogistics.LogisticsApp.onCreate(LogisticsApp.kt:53)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5740)
at android.app.ActivityThread.-wrap1(Unknown Source)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by java.lang.NoSuchMethodException: values []
at java.lang.Class.getMethod(Class.java:2068)
at java.lang.Class.getDeclaredMethod(Class.java:2047)
at java.lang.Enum$1.create(Enum.java:268)
at java.lang.Enum$1.create(Enum.java:263)
at libcore.util.BasicLruCache.get(BasicLruCache.java:58)
at java.lang.Enum.getSharedConstants(Enum.java:289)
at java.lang.Enum.valueOf(Enum.java:244)
at io.multimoon.colorful.ThemeColor.valueOf(Unknown Source:2)
at io.multimoon.colorful.ThemeColorInterface$Companion.parse(ThemeColor.kt:18)
at io.multimoon.colorful.ColorfulKt.initColorful(Colorful.kt:29)
at com.noodoe.nexlogistics.LogisticsApp.onCreate(LogisticsApp.kt:53)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5740)
at android.app.ActivityThread.-wrap1(Unknown Source)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
So I added these proguard settings to make app open successfully:
-keep class io.multimoon.colorful.** { *; }
-dontwarn io.multimoon.colorful.**
Does anyone have other ideas?
When I apply theme in my setting activity, return to MainActivity, then go to setting activity, I got the following error log(which seems not influence my app):
12-28 17:37:49.563 23151-23151/com.dante.girls E/ActivityThread: Performing pause of activity that is not resumed: {com.dante.girls/com.dante.girls.MainActivity}
java.lang.RuntimeException: Performing pause of activity that is not resumed: {com.dante.girls/com.dante.girls.MainActivity}
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3352)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3340)
at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3315)
at android.app.ActivityThread.-wrap13(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Each time I do those actions I got that error, so it's not occasional.
Colorful uses a android's ability to mix style files together to build complex themes. Since these are stored in XML files in a standard naming format, the functionality could be added to allow users to provide additional colors via style files.
At least to be able to set the colorPrimaryDark
as well through Colorful would be very nice.
Additional text colors would be nice as well altough it's not that important...
As the AndroidX version of AppCompat is stable now, I'd recommend to update.
@garretyoder Using "setPrimaryColor" and "setCustomThemeOverride" at the same time, "setPrimaryColor" will not work when the application is restarted
Colorful().edit()
.setAccentColor(ThemeColor.PINK)
.setCustomThemeOverride(R.style.AppThemeWhite)
.apply(getContext(), () -> {
recreate();
return null;
});
ColorfulKt.Colorful().apply(this, false, true);
<style name="AppThemeWhite" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/white</item>
<item name="toolbarStyle">@style/AppThemeWhite.Toolbar</item>
</style>
<style name="AppThemeWhite.Toolbar" parent="@style/Widget.AppCompat.Toolbar">
<item name="titleTextAppearance">@style/AppThemeWhite.Toolbar.Title</item>
<item name="subtitleTextAppearance">@style/AppThemeWhite.Toolbar.Subtitle</item>
</style>
<style name="AppThemeWhite.Toolbar.Title" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textColor">?attr/colorAccent</item>
</style>
<style name="AppThemeWhite.Toolbar.Subtitle" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Subtitle">
<item name="android:textColor">?attr/colorAccent</item>
</style>
i want app and status bar same color but its bot work
` Defaults defaults = new Defaults(
ThemeColor.GREEN,
ThemeColor.GREEN,
false,
false,
0);
initColorful(this, defaults);`
it show status bar different green ...
The Readme states:
The apply method optionally takes a high-order function as a argument. This serves as a callback that will be triggered once Colorful has finished it's theme changes
However, ThemeEditor#apply()
infers a @nonnull annotation on both of its arguments.
If this is to match the readme, the callback should be optional, and therefore must have a null check before being called.
I believe this will also make things easier for non-Kotlin users to make use of.
Thanks
I'm getting the error with the latest build 2.3.3 in my compiler
error: style attribute 'attr/colorSecondary (aka com.***.**:attr/colorSecondary)' not found.
Errors are pointing to the values.xml file in Colorful lib specifically accent1 to accent 20
Kindly assist.
I'm on android support lib 27.1.1
@garretyoder Dark/Light themeing will not work when override is disable, I try using "setCustomThemeOverride" to set it in style , when I changed Light to the Dark theme, but it will not change immediately, Only change after restarting the app. What did i do wrong? How should I correct it?
Colorful().edit()
.setCustomThemeOverride(darkTheme ? R.style.AppThemeDark: R.style.AppTheme)
.apply(getContext(), () -> {
recreate();
return null;
});
ColorfulKt.Colorful().apply(this, false, true);
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
<style name="AppThemeDark" parent="Theme.AppCompat.NoActionBar">
</style>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.