L lymey Active Member Licensed User Longtime User Aug 18, 2013 #1 Hi, I have been trying to figure out how to change the cursor color in an EditText - mainly because the default is white in 4.x, and I dont want black/dark backgrounds in EditText boxes! I looked on the net, and the rsults for java developers involve changing .xml layout files, which I believe we can't do using B4A unless you create a library?? Anyway, is there a way in B4A of changing the EditText cursor color to black not white? Use Reflection? Thanks!
Hi, I have been trying to figure out how to change the cursor color in an EditText - mainly because the default is white in 4.x, and I dont want black/dark backgrounds in EditText boxes! I looked on the net, and the rsults for java developers involve changing .xml layout files, which I believe we can't do using B4A unless you create a library?? Anyway, is there a way in B4A of changing the EditText cursor color to black not white? Use Reflection? Thanks!
Erel B4X founder Staff member Licensed User Longtime User Aug 18, 2013 #2 It is not possible to change the cursor programmatically (in Java or Basic4android). The only way is with an XML attribute. This means that you will also need to create an XML layout. I think that there is a library that allows you to load XML layouts. Upvote 0
It is not possible to change the cursor programmatically (in Java or Basic4android). The only way is with an XML attribute. This means that you will also need to create an XML layout. I think that there is a library that allows you to load XML layouts.
L lymey Active Member Licensed User Longtime User Aug 18, 2013 #3 Thanks Erel, I took a look through the lists of libraries and can't find one that does that. Does anyone know which one that is. Perhaps there are examples that someone has posted of using .xml files with a B4A? I have no idea where to start! Upvote 0
Thanks Erel, I took a look through the lists of libraries and can't find one that does that. Does anyone know which one that is. Perhaps there are examples that someone has posted of using .xml files with a B4A? I have no idea where to start!
L lymey Active Member Licensed User Longtime User Aug 18, 2013 #4 Erel said: It is not possible to change the cursor programmatically (in Java or Basic4android). The only way is with an XML attribute. This means that you will also need to create an XML layout. I think that there is a library that allows you to load XML layouts. Click to expand... I found this solution for java developers, is there any example of how I could incorporate an XML layout into my B4A project? I could then try the solution in this link: http://stackoverflow.com/questions/7238450/set-edittext-cursor-color Upvote 0
Erel said: It is not possible to change the cursor programmatically (in Java or Basic4android). The only way is with an XML attribute. This means that you will also need to create an XML layout. I think that there is a library that allows you to load XML layouts. Click to expand... I found this solution for java developers, is there any example of how I could incorporate an XML layout into my B4A project? I could then try the solution in this link: http://stackoverflow.com/questions/7238450/set-edittext-cursor-color
Erel B4X founder Staff member Licensed User Longtime User Aug 18, 2013 #5 I'm not sure that there is a library available. I thought that this library allows you to load XML files: http://www.b4x.com/android/forum/threads/library-viewextender-expand-your-views.21822/#content this is not the case however. It should be quite simple to create a library that loads an XML file. Upvote 0
I'm not sure that there is a library available. I thought that this library allows you to load XML files: http://www.b4x.com/android/forum/threads/library-viewextender-expand-your-views.21822/#content this is not the case however. It should be quite simple to create a library that loads an XML file.
L lymey Active Member Licensed User Longtime User Aug 18, 2013 #6 Erel said: I'm not sure that there is a library available. I thought that this library allows you to load XML files: http://www.b4x.com/android/forum/threads/library-viewextender-expand-your-views.21822/#content this is not the case however. It should be quite simple to create a library that loads an XML file. Click to expand... Perhaps I am confused - are we talking about the same thing? I don't want to load an xml file, I just want to be able to change the layout of EditText so that I can have a black cursor. My assumption was that I could add an .xml file to the resources of my B4A project and do that? But I have no idea how to implement that in my B4A project. The Java folks seem to have some layout solutions - http://stackoverflow.com/questions/7238450/set-edittext-cursor-color I just don't know how to do it with B4A? Totally confused! Upvote 0
Erel said: I'm not sure that there is a library available. I thought that this library allows you to load XML files: http://www.b4x.com/android/forum/threads/library-viewextender-expand-your-views.21822/#content this is not the case however. It should be quite simple to create a library that loads an XML file. Click to expand... Perhaps I am confused - are we talking about the same thing? I don't want to load an xml file, I just want to be able to change the layout of EditText so that I can have a black cursor. My assumption was that I could add an .xml file to the resources of my B4A project and do that? But I have no idea how to implement that in my B4A project. The Java folks seem to have some layout solutions - http://stackoverflow.com/questions/7238450/set-edittext-cursor-color I just don't know how to do it with B4A? Totally confused!
Erel B4X founder Staff member Licensed User Longtime User Aug 18, 2013 #7 This option will only work if you design the layout in a XML file (like done with Eclipse). Not with the designer or code. Upvote 0
This option will only work if you design the layout in a XML file (like done with Eclipse). Not with the designer or code.
L lymey Active Member Licensed User Longtime User Aug 18, 2013 #8 Erel said: This option will only work if you design the layout in a XML file (like done with Eclipse). Not with the designer or code. Click to expand... Yes, I understand. But assuming I can get the EditText layout .xml file created with the cursor the right color, how do I then make sure that it works with B4A? For example, the following is a solution posted on a java/Android forum that will change the cursor color - In Layout: <EditTextandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:textCursorDrawable="@drawable/color_cursor"/> Than create drawable xml: color_cursor <?xml version="1.0" encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"><sizeandroid:width="3dp"/><solidandroid:color="#000000"/></shape> Click to expand... In the example I modified the color to #000000 So my question is what do I have to do to make sure that B4A picks up the Layout change? For example - what is the 'Layout' file and how do I add this change? Upvote 0
Erel said: This option will only work if you design the layout in a XML file (like done with Eclipse). Not with the designer or code. Click to expand... Yes, I understand. But assuming I can get the EditText layout .xml file created with the cursor the right color, how do I then make sure that it works with B4A? For example, the following is a solution posted on a java/Android forum that will change the cursor color - In Layout: <EditTextandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:textCursorDrawable="@drawable/color_cursor"/> Than create drawable xml: color_cursor <?xml version="1.0" encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"><sizeandroid:width="3dp"/><solidandroid:color="#000000"/></shape> Click to expand... In the example I modified the color to #000000 So my question is what do I have to do to make sure that B4A picks up the Layout change? For example - what is the 'Layout' file and how do I add this change?
Erel B4X founder Staff member Licensed User Longtime User Aug 19, 2013 #9 This is not relevant unless: 1. Someone creates a library that loads layouts from XML files. 2. You declare the layout in XML (instead of the designer or programmatically). Upvote 0
This is not relevant unless: 1. Someone creates a library that loads layouts from XML files. 2. You declare the layout in XML (instead of the designer or programmatically).
L lymey Active Member Licensed User Longtime User Aug 20, 2013 #10 Erel said: This is not relevant unless: 1. Someone creates a library that loads layouts from XML files. 2. You declare the layout in XML (instead of the designer or programmatically). Click to expand... Ok. So just so I understand - I would have to create a library that creates a new view to replace the current EditText with the ability to set the cursor property to something other than white - or - I would have to abandon the designer layouts and/or programmatically coded interface, and create the entire layout with all the views used in my app in XML in order to have an EditText with a cursor color other than white? Does that really mean then that every app created with B4A for Android 4.x has to be black or dark with the text set to white in order to have a visible cursor? Sorry If I am missing something! Upvote 0
Erel said: This is not relevant unless: 1. Someone creates a library that loads layouts from XML files. 2. You declare the layout in XML (instead of the designer or programmatically). Click to expand... Ok. So just so I understand - I would have to create a library that creates a new view to replace the current EditText with the ability to set the cursor property to something other than white - or - I would have to abandon the designer layouts and/or programmatically coded interface, and create the entire layout with all the views used in my app in XML in order to have an EditText with a cursor color other than white? Does that really mean then that every app created with B4A for Android 4.x has to be black or dark with the text set to white in order to have a visible cursor? Sorry If I am missing something!
Informatix Expert Licensed User Longtime User Aug 20, 2013 #11 lymey said: Ok. So just so I understand - I would have to create a library that creates a new view to replace the current EditText with the ability to set the cursor property to something other than white - or - I would have to abandon the designer layouts and/or programmatically coded interface, and create the entire layout with all the views used in my app in XML in order to have an EditText with a cursor color other than white? Click to expand... Did you ever create a view in Java? lymey said: Does that really mean then that every app created with B4A for Android 4.x has to be black or dark with the text set to white in order to have a visible cursor? Click to expand... No, it depends on the style/theme defined in the Manifest. If you use the Dark Holo theme (default), then you're right. If you use a Light Holo Theme, it's the contrary. Upvote 0
lymey said: Ok. So just so I understand - I would have to create a library that creates a new view to replace the current EditText with the ability to set the cursor property to something other than white - or - I would have to abandon the designer layouts and/or programmatically coded interface, and create the entire layout with all the views used in my app in XML in order to have an EditText with a cursor color other than white? Click to expand... Did you ever create a view in Java? lymey said: Does that really mean then that every app created with B4A for Android 4.x has to be black or dark with the text set to white in order to have a visible cursor? Click to expand... No, it depends on the style/theme defined in the Manifest. If you use the Dark Holo theme (default), then you're right. If you use a Light Holo Theme, it's the contrary.
L lymey Active Member Licensed User Longtime User Aug 20, 2013 #12 Informatix said: Did you ever create a view in Java? Click to expand... Nope, that's why I am using B4A, I would have to get the Java/Android for Dummies books out and teach myself how to do it...then figure out how to create the library for B4A to use it. [/quote]No, it depends on the style/theme defined in the Manifest. If you use the Dark Holo theme (default), then you're right. If you use a Light Holo Theme, it's the contrary.[/quote] I don't define a theme in the manifest file. The idea is to create an app that works on all versions of android from 2.x to 4.x which so far has been easy enough without having to change the look and feel....seamless upgrades etc. Some customers will have earlier versions, different themes set, but the app stays the same, the EditText backgrounds, text, and cursor (used to be) were controllable. So any suggestions? Upvote 0
Informatix said: Did you ever create a view in Java? Click to expand... Nope, that's why I am using B4A, I would have to get the Java/Android for Dummies books out and teach myself how to do it...then figure out how to create the library for B4A to use it. [/quote]No, it depends on the style/theme defined in the Manifest. If you use the Dark Holo theme (default), then you're right. If you use a Light Holo Theme, it's the contrary.[/quote] I don't define a theme in the manifest file. The idea is to create an app that works on all versions of android from 2.x to 4.x which so far has been easy enough without having to change the look and feel....seamless upgrades etc. Some customers will have earlier versions, different themes set, but the app stays the same, the EditText backgrounds, text, and cursor (used to be) were controllable. So any suggestions?
Informatix Expert Licensed User Longtime User Aug 20, 2013 #13 The cursor drawable can only be changed since Honeycomb, so with Gingerbread and older versions you're stuck with the dark and light themes provided. Upvote 0
The cursor drawable can only be changed since Honeycomb, so with Gingerbread and older versions you're stuck with the dark and light themes provided.
L lymey Active Member Licensed User Longtime User Aug 20, 2013 #14 Ok. 2.2 and 2.3.x have the cursor showing as black - This is was not a problem since the backgrounds of the EditText boxes are White/SmokeWhite. It made no difference what the user did or if your device was black with white text or white with black text. In 4.x the cursor changes to white if you your phone is set to the default theme (dark)...which the vast majority seem to be... and vice versa. If your interface uses EditText backgrounds that are white/light colored, and the device theme is black - you are out of luck...no cursor! Since you cannot tell if the theme choice is dark or light, it is logical to design your app so that you control the interface look and feel and user experience within your app - which means being able to set the EditText background, text color, and cursor. I am looking for a solution to set the cursor to black in an EditText box, regardless of what theme is selected. The folks in 'Java land' have recognized this problem and have come up with what appear to be simple solutions (for them any way!) to make sure that they can control the interface look and feel, and overcome the 'disappearing cursor'. So the question was: How to change the EditText cursor color in B4A? Answers if I understand them so far: 1 - Create a library to replace the current EditText view with one that has the ability to change the cursor color. 2 - Don't use B4A to create the layout, and use XML. Option 1 - is that correct? - and how hard is that to do (if you don't have the skills then very!)? Option 2 - Wow! Upvote 0
Ok. 2.2 and 2.3.x have the cursor showing as black - This is was not a problem since the backgrounds of the EditText boxes are White/SmokeWhite. It made no difference what the user did or if your device was black with white text or white with black text. In 4.x the cursor changes to white if you your phone is set to the default theme (dark)...which the vast majority seem to be... and vice versa. If your interface uses EditText backgrounds that are white/light colored, and the device theme is black - you are out of luck...no cursor! Since you cannot tell if the theme choice is dark or light, it is logical to design your app so that you control the interface look and feel and user experience within your app - which means being able to set the EditText background, text color, and cursor. I am looking for a solution to set the cursor to black in an EditText box, regardless of what theme is selected. The folks in 'Java land' have recognized this problem and have come up with what appear to be simple solutions (for them any way!) to make sure that they can control the interface look and feel, and overcome the 'disappearing cursor'. So the question was: How to change the EditText cursor color in B4A? Answers if I understand them so far: 1 - Create a library to replace the current EditText view with one that has the ability to change the cursor color. 2 - Don't use B4A to create the layout, and use XML. Option 1 - is that correct? - and how hard is that to do (if you don't have the skills then very!)? Option 2 - Wow!
Informatix Expert Licensed User Longtime User Aug 20, 2013 #15 lymey said: Since you cannot tell if the theme choice is dark or light, it is logical to design your app so that you control the interface look and feel and user experience within your app - which means being able to set the EditText background, text color, and cursor. Click to expand... That's why I suggested to set a theme in the Manifest. You'll have no trouble this way. My initial answer was longer than that but a Ctrl+Z, instead of cancelling my last change, completely erased my post. As I don't have the courage to re-type everything, here's a summary: - you need to create a library in Java. It's not possible with B4A. Doing this library is not very difficult but if you never wrote a line in Java.... - it's cumbersome compared to a theme that you force in the Manifest Upvote 0
lymey said: Since you cannot tell if the theme choice is dark or light, it is logical to design your app so that you control the interface look and feel and user experience within your app - which means being able to set the EditText background, text color, and cursor. Click to expand... That's why I suggested to set a theme in the Manifest. You'll have no trouble this way. My initial answer was longer than that but a Ctrl+Z, instead of cancelling my last change, completely erased my post. As I don't have the courage to re-type everything, here's a summary: - you need to create a library in Java. It's not possible with B4A. Doing this library is not very difficult but if you never wrote a line in Java.... - it's cumbersome compared to a theme that you force in the Manifest
L lymey Active Member Licensed User Longtime User Aug 21, 2013 #16 So presumably you have to have the themes in the resources directory for them to be referenced from the manifest file? I tried this example to get an understanding of how it might work: http://www.b4x.com/android/forum/threads/theme-based-on-version-tutorial.27624/ and received the following errors when I tried to compile the project: Parsing code. 0.00 Compiling code. 0.03 Compiling layouts code. 0.01 Generating R file. Error res\values-v11\styles.xml:4: error: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.Holo.Light'. res\values-v11\styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.Holo.Light.NoActionBar'. res\values-v11\styles.xml:12: error: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.Holo.Light.Panel'. Am I right in assuming that there additional .xml files that I have to add to the resources directory, and where do I get them? Upvote 0
So presumably you have to have the themes in the resources directory for them to be referenced from the manifest file? I tried this example to get an understanding of how it might work: http://www.b4x.com/android/forum/threads/theme-based-on-version-tutorial.27624/ and received the following errors when I tried to compile the project: Parsing code. 0.00 Compiling code. 0.03 Compiling layouts code. 0.01 Generating R file. Error res\values-v11\styles.xml:4: error: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.Holo.Light'. res\values-v11\styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.Holo.Light.NoActionBar'. res\values-v11\styles.xml:12: error: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.Holo.Light.Panel'. Am I right in assuming that there additional .xml files that I have to add to the resources directory, and where do I get them?
Informatix Expert Licensed User Longtime User Aug 21, 2013 #17 Why do you always take the hardest path? This single line in the Manifest is enough: SetApplicationAttribute(android:theme, "@android:style/Theme.Holo") or SetApplicationAttribute(android:theme, "@android:style/Theme.Holo.Light") Upvote 0
Why do you always take the hardest path? This single line in the Manifest is enough: SetApplicationAttribute(android:theme, "@android:style/Theme.Holo") or SetApplicationAttribute(android:theme, "@android:style/Theme.Holo.Light")
L lymey Active Member Licensed User Longtime User Aug 22, 2013 #18 Informatix said: Why do you always take the hardest path? This single line in the Manifest is enough: SetApplicationAttribute(android:theme, "@android:style/Theme.Holo") or SetApplicationAttribute(android:theme, "@android:style/Theme.Holo.Light") Click to expand... Hahahaha..good point! I added SetApplicationAttribute(android:theme, "@android:style/Theme.Holo.Light") via the manifest editor, and it updated the manifest file correctly. BUT this is the error I get when I try to compile: Parsing code. 0.34 Compiling code. 0.42 Compiling layouts code. 0.01 Generating R file. Error AndroidManifest.xml:25: error: Error: No resource found that matches the given name (at 'theme' with value '@android:style/Theme.Holo.Light'). Am I missing something else? Upvote 0
Informatix said: Why do you always take the hardest path? This single line in the Manifest is enough: SetApplicationAttribute(android:theme, "@android:style/Theme.Holo") or SetApplicationAttribute(android:theme, "@android:style/Theme.Holo.Light") Click to expand... Hahahaha..good point! I added SetApplicationAttribute(android:theme, "@android:style/Theme.Holo.Light") via the manifest editor, and it updated the manifest file correctly. BUT this is the error I get when I try to compile: Parsing code. 0.34 Compiling code. 0.42 Compiling layouts code. 0.01 Generating R file. Error AndroidManifest.xml:25: error: Error: No resource found that matches the given name (at 'theme' with value '@android:style/Theme.Holo.Light'). Am I missing something else?
Erel B4X founder Staff member Licensed User Longtime User Aug 22, 2013 #19 You should reference android.jar from platform level 14 or above under Tools - Configure Paths (this theme is not available in older devices, they will use the default theme instead). Upvote 0
You should reference android.jar from platform level 14 or above under Tools - Configure Paths (this theme is not available in older devices, they will use the default theme instead).
L lymey Active Member Licensed User Longtime User Aug 22, 2013 #20 Erel said: You should reference android.jar from platform level 14 or above under Tools - Configure Paths (this theme is not available in older devices, they will use the default theme instead). Click to expand... Thank you both for your help (and patience), that fixed it! Just in case anybody lost track - to show the cursor as dark in a light colored text box with the dark default theme: Add - SetApplicationAttribute(android:theme, "@android:style/Theme.Holo.Light") to the manifest editor, and then ensure that the path to the android.jar file looks something like this: C:\Android_x86\Android\android-sdk\platforms\android-14\android.jar Upvote 0
Erel said: You should reference android.jar from platform level 14 or above under Tools - Configure Paths (this theme is not available in older devices, they will use the default theme instead). Click to expand... Thank you both for your help (and patience), that fixed it! Just in case anybody lost track - to show the cursor as dark in a light colored text box with the dark default theme: Add - SetApplicationAttribute(android:theme, "@android:style/Theme.Holo.Light") to the manifest editor, and then ensure that the path to the android.jar file looks something like this: C:\Android_x86\Android\android-sdk\platforms\android-14\android.jar