Android ColorPickerDialog show black, white colors - android

I have this code running: Color picker with usage in android perfectly, althought it doens't show the color white, gray, black, etc..to choose.
What do I need to change in code for being able to choose that colors?
Thank you!

You can customize the one that you mentioned in your question also. You will need to do some modifications in the ColorPickerView class.
You can also try an alternative color picker available in the below link.
Download the zip file from
http://code.google.com/p/yuku-android-util/source/browse/#git%2FAmbilWarna
Extract the zip file.
Import the library project (AmbilWarna) into workspace as you would do for any other library projects like google play services or actionbarsherlock.
Reference the library in your android project
On Button Click or some action
AmbilWarnaDialog dialog = new AmbilWarnaDialog(MainActivity.this, Color.RED, new OnAmbilWarnaListener() {
#Override
public void onOk(AmbilWarnaDialog dialog, int color) {
// color is the color selected by the user.
mPaint.setColor(color); // set color here
}
#Override
public void onCancel(AmbilWarnaDialog dialog) {
// cancel was selected by the user
}
});
dialog.show();

Related

Apply similar looking styles to AlertDialog box for different Android versions

I want to make the AlertDialog box for my app look like the ones on Android > 6.0.0 ( as depicted in the following screenshots) for all lower android version till 4.4.4. I have applied a custom style for the dialog box.
Following is the style in styles.xml for AlertDialog:
<style
name="AlertDialogCustom" parent="ThemeOverlay.AppCompat.Dialog.Alert">
<item name="android:textColor">#color/blue</item>
<item name="android:textColorSecondary">#color/white</item>
<item name="android:textColorPrimary">#color/white</item>
<item name="android:background">#color/dark_grey</item>
<item name="android:backgroundDimAmount">0.3</item>
</style>
Following is how I applied the style in java:
new AlertDialog.Builder(new ContextThemeWrapper(context, R.style.AlertDialogCustom))
.setMessage("Why is DialogBox Style Inconsistent through different android versions?")
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton("Yes", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
//Do Something
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
//Do Something
}
})
.show();
As a get around I managed to at least change the text color to white on the dark background by using:
if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1)
style = android.R.style.Theme_Material_Dialog;
else
style = R.style.AlertDialogCustom;
So far I have tried making seperate style for lower Android version and apply them via java by detecting Android version. But, I am unable to replicate the style of AlertDialog box on Android 6+ on lower android versions till 4.4.4. And I am unable to find a solution on the internet.
There is an anomaly though; if I apply my custom style on Rate this app provided by kobakei the resulting RateThisApp dialog looks the same on all the android versions. So I believe styling the AlertDialog in a particular manner should fix the issue.
This is what I want - To make the AlertDialog box on Android 4.4.4 and 5.1.0 to look like the one in Android 6.0.0 and higher by using suitable styles. And why does the textColor and textColorPrimary attributes does not get applied on lower android versions?
If the resource provided in my question is insufficient please let me know in the comment, I will share more details.
Here are the screenshots of AlertDialog box on different Android versions with the same style applied.
Android >= 6.0.0
Android = 5.1.0
Android 4.4.4
For more flexibility, you can just create your custom dialog class with a custom layout.
It will give you better control over the way the layout looks.
You can create very complicated UI in your dialog without writing tons of code
You can simply call your dialog like this :
CustomDialog customDialog = new CustomDialog();
customDialog.show();
And you can manage click listeners and more events inside your dialog class instead of adding those code lined inside your activity and make it super big and hard to understand.
Here is an example:
public class CustomDialog extends Dialog {
private ImageView imageView;
private Context dialogContext;
public CustomDialog (#NonNull Context context) {
super(context);
setContentView(R.layout.full_size_image_dialog); .. //your layout
dialogContext = context;
imageView = findViewById(R.id.full_size_image); //controll your views (use any view, the image view is only an example)
}
public void someMethod() {
}
}
}

Android AlertDialog.Builder displays blank unless a theme is supplied

I have recently begun work on an existing android app and noticed that one of the modals displays as a white blank square. I did some research and someone suggested that supplying a theme should fix it. I tried this and it does fix the issue but i don't understand why this was working without it and now its not. The code we use to initialize the AlertDialog looks like this
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setItems(R.array.media_resume_options, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//handle selection logic here
//......
}
});
builder.create().show();
I can fix it by changing the instantiation line to
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_DARK );
I don't see any changes to this part of the code that might have caused it. Could it be affected by something else? whats the potential risk that it might affect other dialogs?
It can't be blank,the textcolor and background color both are white that's why you think it is blank.
How to change default text color of dialogbox is explained here
Change dialog text color on 5.0+

Getting Memory Out For using color picker

I am getting Memory out error in Bitmap for one of my Play Store Apps. In this app I used color Picker for choosing color by User. And that gives me the error.
My used color Picker is:
https://github.com/chiralcode/Android-Color-Picker
Its normally take 6 to 7 MB memory.
Now I can't solve this problem. Is there any better Color Picker?
Thanks in advance.
If you're looking for a great new android color picker that use material design I have forked an great project from github and made a simple-to-use android color picker dialog.
This is the project: Android Color Picker
HOW TO USE IT
Adding the library to your project
The aar artifact is available at the jcenter repository. Declare the repository and the
dependency in your build.gradle.
(root)
repositories {
jcenter()
}
(module)
dependencies {
compile 'com.pes.materialcolorpicker:library:1.0.1'
}
Use the library
Create a color picker dialog object
final ColorPicker cp = new ColorPicker(MainActivity.this, defaultColorR, defaultColorG, defaultColorB);
defaultColorR, defaultColorG, defaultColorB are 3 integer ( value 0-255) for the initialization of the color picker with your custom color value. If you don't want to start with a color set them to 0 or use only the first argument
Then show the dialog (when & where you want) and save the selected color
/* Show color picker dialog */
cp.show();
/* On Click listener for the dialog, when the user select the color */
Button okColor = (Button)cp.findViewById(R.id.okColorButton);
okColor.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
/* You can get single channel (value 0-255) */
selectedColorR = cp.getRed();
selectedColorG = cp.getGreen();
selectedColorB = cp.getBlue();
/* Or the android RGB Color (see the android Color class reference) */
selectedColorRGB = cp.getColor();
cp.dismiss();
}
});
That's all :)

WebView/Phonegap change select (dropdown) style

In my AndroidManifest.xml file I set up the theme to be Holo.Light (or even Holo)
The alert dialog are being designed according to the Holo Theme (either light or dark) but the dropdowns (select) are looking like this:
Is there a way to style the dropdowns like Google Chrome and other apps do?
The native select looks like this:
There is no easy way to achieve that. What you need to do there is to build a native plugin that will open a custom dialog when you click on a <select>.
That dropdown you want to get rid of is the default view for selects on webviews, opposed to the second one that was built in chrome. To help getting you started:
//get all the options and store in an array
var values = $.map($('#group_select option'), function(e) { return e.value; });
//Native function that gets the options and display a dialog
function void showDialog(String[] values){
AlertDialog.Builder b = new Builder(this);
b.setTitle("Example");
b.setItems(values, new OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
switch(which){
case 0:
//call some javascript method to use this value here
break;
case 1:
//call some javascript method to use this value here
break;
}
}
});
b.show();
}
Make sure to set your theme to Holo or Holo.Light as you prefer, and do your preferred bit to call a native code from the javascript layer whenever there is a click on a select element.
You can use jQuery mobile and get yourself a customized theme from from their themeroller
or
Try using "android:Theme" as your parent theme as
<style name="YourTheme" parent="android:Theme">
it is the old android theme and gives the style you are looking for
or you can also specifically change
<item name="spinnerStyle">#android:style/Widget.Spinner</item>
<item name="spinnerDropDownItemStyle">#android:style/Widget.DropDownItem.Spinner</item>
<item name="spinnerItemStyle">#android:style/Widget.TextView.SpinnerItem</item
to create your own style

Color Picker how to change TextView

I have a problem.
How to use ColorPickerDialog ?
How do I set ColorPickerDialog so as to change my text color?
Please have a look over this existing code..
http://www.yougli.net/android/a-photoshop-like-color-picker-for-your-android-application/
You can use this project instead of a demo app
// initialColor is the initially-selected color to be shown in the rectangle on the left of the arrow.
// for example, 0xff000000 is black, 0xff0000ff is blue. Please be aware of the initial 0xff which is the alpha.
AmbilWarnaDialog dialog = new AmbilWarnaDialog(this, initialColor, new OnAmbilWarnaListener() {
#Override
public void onOk(AmbilWarnaDialog dialog, int color) {
// color is the color selected by the user.
}
#Override
public void onCancel(AmbilWarnaDialog dialog) {
// cancel was selected by the user
}
});
dialog.show();
Be careful to this (I never used it myself):
You need to link against Android 3.0 or higher since there is an XML
attribute layerType in use. This doesn't mean you can use this only
for applications requiring Android 3.0 to operate. It works even in
Android 1.6. You just need to select Android 3.0 (API level 11) on the
project settings.

Categories

Resources