#DEPRECATED
https://github.com/hafizahmmed)
Credits for the logo goes to Hafiz Ahmmed (ColorBox library
Features
- Dynamic color preview;
- Change the color through Alpha, Red, Green, and Blue sliders;
- Clearable recent colors;
- Material palettes (>200 colors!);
- ColorBox preference;
- Themes (Light, Dark, Black);
- Easy to implement;
Sample Project
You can download the latest sample APK from this repo here: https://github.com/enricocid/ColorBox-library/blob/master/files/release/app-release.apk
Gradle Dependency
Repository
The Gradle dependency is available via jCenter. jCenter is the default Maven repository used by Android Studio.
The minimum API level supported by this library is API 21 (Lollipop).
Download
- If You are using gradle:3.0+ You should use 'implementation' configuration. Add the following dependency to your project's build.gradle:
dependencies {
// ... other dependencies here
implementation 'com.github.enricocid:cbl:1.1.1'
}
- For gradle versions < 3.0 use 'compile' configuration:
dependencies {
// ... other dependencies here
compile 'com.github.enricocid:cbl:1.1.1'
}
Usage
To display the color box simply:
ColorBox.showColorBox(String tag, Activity activity, int theme);
tag: it's a string used to identify the ColorBox.
theme: Possible values are:
- ColorBox.LIGHT;
- ColorBox.DARK;
- ColorBox.BLACK;
Usage instructions for Preferences
In Your preferences XML add:
<com.github.colorbox.ColorBoxPreference android:key="the_key_u_want" android:title="@string/your_string"/>
note: don't forget to add a (different) key and a title for every ColorBoxPreference You add in Your preferences XML.
You can set the theme of the ColorBox by adding the setTheme attribute. The possible values are 1 and 2. The default value is 0, corresponding to the light theme (You don't need to specify this attribute if You want to keep the light theme).
- For Dark theme (1):
<com.github.colorbox.ColorBoxPreference
app:setTheme="1"
android:key="the_key_u_want" android:title="@string/your_string"/>
- For Black theme (2):
<com.github.colorbox.ColorBoxPreference
app:setTheme="2"
android:key="the_key_u_want" android:title="@string/your_string"/>
In You Preference fragment (onResume) add this
@Override
public void onResume() {
super.onResume();
ColorBox.registerPreferenceUpdater(Activity activity);
}
To retrieve the color:
int color = ColorBox.getColor(String tag, Context context);
Utilities:
ColorBox.getComplementaryColor(int colorToInvert)
Returns inverted color:
ColorBox.getHexadecimal(int color)
Returns the hexadecimal code from color.
ColorBox.isColorDark(int color)
Determine if the color is dark or light.