Skip to content
This repository has been archived by the owner on Nov 12, 2020. It is now read-only.

XfxEntry and XfxComboBox colors #6

Closed
ChaseFlorell opened this issue Mar 19, 2017 · 27 comments
Closed

XfxEntry and XfxComboBox colors #6

ChaseFlorell opened this issue Mar 19, 2017 · 27 comments
Assignees

Comments

@ChaseFlorell
Copy link
Contributor

Bug

  • Version Number of Control: 1.0.1.4
  • Device Tested On: Any Android
  • Simulator Tested On: Any Android

Expected Behavior

Setting Placeholder color will set the color of the placeholder

Actual Behavior

Setting the Placeholder color has no effect

Steps to reproduce the Behavior

Try to set the color of a placeholder

Feature Request:

There's also a feature request attached. Currently there's no way to set the Highlight color of a control. The Highlight color should update the underline as well as the label of an XfxEntry and an XfxComboBox.

Api Change:

public static readonly BindableProperty HighlightColorProperty = BindableProperty.Create(nameof(HighlightColor),
    typeof(Color),
    typeof(XfxEntry),
    Color.Accent);

/// <summary>
/// Sets the color of the active label and active underline. This is a bindable property.
/// </summary>
public Color HighlightColor
{
    get { return (Color) GetValue(HighlightColorProperty); }
    set { SetValue(HighlightColorProperty, value); }
}
@elyfran
Copy link

elyfran commented Mar 27, 2017

+1

@ghost
Copy link

ghost commented Mar 31, 2017

Any progress in this bug?:(

@ChaseFlorell
Copy link
Contributor Author

ChaseFlorell commented Mar 31, 2017 via email

@ghost
Copy link

ghost commented Mar 31, 2017

Can i help you, or you wanna to handle this bug yourself? I need this functionality :(

@ChaseFlorell
Copy link
Contributor Author

ChaseFlorell commented Mar 31, 2017

I'm keen on the help for sure!

So I was originally thinking we'd use HighlightColor, but I'm wondering if we piggyback off of "Focus", and therefore have a FocusedColor and an UnfocusedColor (though I'm definitely open to suggestions).

These would set the color of the floated label and the underline (but not the placeholder). The default FocusedColor should should be Color.Accent and the default UnfocusedColor should be Color.Default.

Also keep in mind that an error will override the underline color to RED, but the floated label stays the same color for it's state.

Feel free to bounce ideas around here, or run with the implementation if you like.

FYI the EditText.Background is where you set the ColorStateList in Android for the underline color, and it's a PITA.

Also note that you don't have to touch the ComboBox as the EntryRenderer will handle it for both.

@ghost
Copy link

ghost commented Mar 31, 2017

Okey i will see what can i do, if i able to get any progress i will tell you :D

@ChaseFlorell
Copy link
Contributor Author

@bryansan did you get anywhere with this?

@ghost
Copy link

ghost commented May 12, 2017 via email

@ChaseFlorell
Copy link
Contributor Author

ChaseFlorell commented Aug 28, 2017

Just a note to say this hasn't fallen off the tracks yet. It is hard however to find time, and every time I go to tackle it I get overwhelmed with Xamarin Forms internal and sealed classes. I just need to make more time.

@DevAnkur
Copy link

I am not sure if this might help, but I modified the cursor color, default hint color, and text color when activated like this:

                  IntPtr intPtrtextViewClass = JNIEnv.FindClass(typeof(EditText));
		IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(intPtrtextViewClass, "mCursorDrawableRes", "I");

//By Setting the value as 0, the color of the cursor will be same as the text color.
		JNIEnv.SetField(EditText.Handle, mCursorDrawableResProperty, 0);

		IntPtr TextInputLayoutViewClass = JNIEnv.FindClass(typeof(TextInputLayout));
		IntPtr mDefaultTextColorProperty = JNIEnv.GetFieldID(TextInputLayoutViewClass, "mDefaultTextColor", @"android/content/res/ColorStateList");
		JNIEnv.SetField(Control.Handle, mDefaultTextColorProperty, JNIEnv.ToJniHandle(new ColorStateList(new int[][] { new int[] { 0 } },
                                                                                                         new int[] { (Element.PlaceholderColor).ToAndroid() })));

		IntPtr mFocusedTextColorProperty = JNIEnv.GetFieldID(TextInputLayoutViewClass, "mFocusedTextColor", @"android/content/res/ColorStateList");
		JNIEnv.SetField(Control.Handle, mFocusedTextColorProperty, JNIEnv.ToJniHandle(new ColorStateList(new int[][] { new int[] { 0 } },
                                                                                                         new int[] { (Element.TextColor).ToAndroid() })));

@ChaseFlorell
Copy link
Contributor Author

ChaseFlorell commented Sep 18, 2017

@DevAnkur does this require anything special in the app styles xml or can it be fully programmatic? I'd be interested in a PR if you have time. I can handle the iOS stuff if you want to PR the Android stuff.

Also note we need to handle the state when active vs inactive.

@DevAnkur
Copy link

@ChaseFlorell , sorry for late reply. For changing the placeholder color and text color, we won't require style.xml, it is fully programmatic.

I will try to work on PR over the weekend but I can't commit as I am a bit occupied with office work.

@ChaseFlorell
Copy link
Contributor Author

Whatever you can do I appreciate. I'm also tied up on other tasks and haven't been able to fully commit to this lately.

@jariwalahetal
Copy link

Is there any update here?

@RudolfVonKrugstein
Copy link

This would be very nice, any updates?

@samukbg
Copy link

samukbg commented Oct 23, 2017

+1

@ChaseFlorell
Copy link
Contributor Author

Still super tied up right now. If anyone wants to submit a PR, it'll be greatly appreciated. Otherwise there's going to be a delay until I can dedicate several hours to this one.

@jariwalahetal
Copy link

@ChaseFlorell
I would be happy to help. Can you give me initial guidelines where I can start this?

@RudolfVonKrugstein
Copy link

For me, it would already be a big help, if the color would be set to the Accent/Tint color on iOS (that is what is actually happening in Android). Because that is actually the default color I want to set it to.

I cannot get the project to compile, still working on that here.

But I think this would do the trick. In the iOS Project in FloatLabeledTextField.cs:

Line 30, add:

using Xamarin.Forms.Platform.iOS;

Line 60:
remove

FloatingLabelActiveTextColor = UIColor.Blue;

and add

FloatingLabelActiveTextColor = Xamarin.Forms.Color.Accent.ToUIColor();

If I get the project to compile, I will make a push request.

@ChaseFlorell
Copy link
Contributor Author

@RudolfVonKrugstein definitely a good stop-gap

@RudolfVonKrugstein
Copy link

I added a pull request here: #32

It is not as simple as I wrote a few posts up because one has to be careful at what point the Accent color is set.
But the pull request works for me.

@ChaseFlorell
Copy link
Contributor Author

Merged, thank you @RudolfVonKrugstein .

@jariwalahetal
Copy link

@ChaseFlorell Is it fixed?

@ChaseFlorell
Copy link
Contributor Author

@jariwalahetal no. The merged PR simply makes it so that the color is set to the Accent color on iOS. It is only a stop-gap until we can get the bindings wired up.

@ChaseFlorell
Copy link
Contributor Author

I have completed the iOS (read easy) work.
You can track progress in this branch
https://github.com/XamFormsExtended/Xfx.Controls/tree/issue-%236

@ChaseFlorell
Copy link
Contributor Author

I'm pretty close to being finished this story, however I'm struggling with the underline on Android.
https://github.com/XamFormsExtended/Xfx.Controls/blob/issue-%236/src/Xfx.Controls.Droid/Renderers/XfxEntryRendererDroid.cs#L187

I've asked for help on StackOverflow as I just can't figure this out.
https://stackoverflow.com/q/47688399/124069

@ChaseFlorell
Copy link
Contributor Author

Finally solved the Android debacle. Had to go pure AppCompat.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants