Codename One Keyboard Cover Image - android

I have an Android application with a text field. When I start typing, the keyboard pushes the background image upwards.
I want the image to stay in place and the keyboard to cover it, instead.
Changing the layout to BoxLayout or BorderLayout does not have any effect on the position of the background image, neither does changing scrollable:
container.setScrollableY(false);
form.setScrollableY(false);
How would I achieve keeping the image in place?
One other thing I was unable to figure out was accessing the form with the cursor already in the TextField and the keyboard visible, setting:
textField.requestFocus();
But that also does not have the desired effect.
Any help would be appreciated.

In addition to Shai's answer, you could try placing the TextField parent container in the north of a BorderLayout container and the image container in the center. This could somehow enforce the keyboard to slide over the image in the center.
To answer the part of TextField editing when the form is shown, add below to the TextField form
form.setEditOnShow(textField);
If you already have some text in the TextField, you might want to set below to place the cursor at the end:
CN.callSerially(() -> {
textField.setCursorPosition(textField.getText().length());
form.repaint(); // optional form repainting
});

Text fields must be in a scrollable parent.
If the image and the text field are in the same container and the text field is above the image you might get something closer to the second image. On iOS the scroll region is increased to accommodate the virtual keyboard, on Android the screen is resized to accommodate it.
This can lead to nuanced behavior difference as the size of the screen adapts.

Related

Partially hide Layout programmatically?

What should I do to partially hide some layout from code? Should I play with setMargins?
Basically, I want to detect size of the screen and then I want that element X becomes visible only 10% of its width? I know how to do it all except how to make it partially hidden or offscreen?
Look at these images to see what I want to achieve. Image 1 - UI element is in the center. Image 2 - I set in code it's moved to top offscreen thus becoming only partially visible.
I found out that here as well the best solution is to use Animation (TranslateAnimation) by setting this on the first screen load and setting its speed to minimum value of 1 millisecond. The transition in reality is unnoticeable to a human eye.
Also do not use margins as they simply "push" element from one side without making it goes offset. If you have any child in the layout you want to offset, they all will be squeezed as you increase margin values.
NOTE: if you ever want to use animation on that screen on the element you offset before, take into account the negative value of offset. Otherwise your animation will not look nice. To avoid bumping effect, take special care of fromXDelta value.

Overlapping Text on Button

I'd like to create a button for a calculator with normal and secondary text on it. The picture below outlines it pretty succinctly. My main concern is getting the secondary text to scale well on different devices. This makes me think that I want to use a secondary text view, or find some way to use HTML to render the button secondary text in the button.
The problem I'm running into is that I have no idea what the most scalable and robust way of doing this is.
Is it necessary to create a custom button? Or is there some way to get the button's setText() with HTML.fromHTML() to place the secondary text at the top left corner? So far adding more lines makes the button stretch, and adding specific padding for the button doesn't scale to other devices. I assume a background 9 patch image using the secondary text won't work either, as larger buttons won't scale the secondary text.
Anyone have any pointers? Thanks!

How to add dynamic text entered by user to canvas in android?

I am making an app in which a user enters some text and that text has to be displayed on a rectangle on an image(like a notes-stick on the image, it can be dragged on the image and also re-sized). I am very new to android and i really can't find a way to do so in android through books and google.
I have been designing apps using html, in html we could just style a text-box like we want and add it anywhere on the page. But here i am unable to configure the edit-text to do the same. But i am unable to make the edit-text like a notes-stick and to make it draggable and re-sizable dynamically.
I also tried drawing just a rectangle using canvas.drawrect() ... but how to add text to that dynamically is something which i am unable to figure out.
I am not asking for the entire code ..but please guys give me a head-start to the right direction so that i can try things out and try to figure out a way.. Right now i am badly stuck.
The image below shows how the notes-stick should look like...
If you don't need it to be actually drawn on the canvas itself, using an EditText widget and having both it and your image in a RelativeLayout may be the way to go. You can set max height and width of the EditText, or have it wrap the height so it expands with the text, etc. Just make sure that the EditText widget gets added to the RelativeLayout after the image, so it is on top.

Android - do I need transparent images for header, or with text already on the images?

I am trying to create a header navigation for my app. I want to get rid of spaces between the buttons, and as I understand it, I need to set images as the background.
My question is whether the images should contain the text on them, or be transparent, and I would just put the text on the buttons by the text field in the layout of that button?
Thanks!
You can have it both ways, but I'd recommend setting the text on the images it saves you space and allows more room for change in case you wanna change a word you dont have to edit the image.
And most importantly you let android auto scale you text to fit screen size( if you set to sp of course )

TextView not drawn in Gallery Sometimes

I am using an Android Gallery widget to show a series of Layouts, and I am getting some unusual rendering of the TextViews within it. Sometimes the TextViews are drawn so they appear dimmed or maybe part transparent.
This is android 2.2
Here is what the app does, with some screen shots:
1. User drags and drops onto the Gallery to set change the content. This changes the content of the Gallery View, but setting parts of the layout to visible or Gone.
The screen updates to this. Look carefully and you will see some text above the green buttons that is not rendering correctly.
3.Finally, user drags away from the Gallery and then back. Voila, the text is rendered as expected. Why does it not work in step 2?
And as a final clue, the text also disappears when the user presses to drag the gallery.
See screenshot below. (listed in order Step 1, Step 2, Step 3)
Answering my own question:
I did not set the android:textColor property in the layout.

Categories

Resources