Android Question Virtual Keyboard covers text (again ...)

ostau

Member
Licensed User
Longtime User
Hi there,
I was searching the forum a hours and days but didn't find a solution for my simple problem. I also tried IME, but I didn't get it work.
Here is my sample code
B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim IME As IME
Dim p As Panel
Dim e As EditText
Dim l As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
p.Initialize("panel")
l.Initialize("label")
l.Text = "Labeltext"
p.AddView(l,0%x,60%y,30%x,40%y)
e.Initialize("edittext1")
e.Color = Colors.LightGray
For i = 1 To 20
e.Text = e.Text & i & Chr(10) & Chr(13)
Next
p.AddView(e,30%x,60%y,70%x,40%y)
Activity.AddView(p,0,0,100%x, 100%y)
End Sub

All I want, is that the TextBox and the Label will be visible when the virtual keybord is on and i can scroll through all 20 lines.
On my device (Galaxy Tab3) - when the Keyboard is on - the top of the TextBox and the height changes, depending which line I click or which line is shown. Sometimes I see 10 lines, then the TextBox shrinks to 1,5 lines.

Could anyone help me out?

Kind regards, Oskar
 

DonManfred

Expert
Licensed User
Longtime User
search for "adjust pan" in forum... There need to be a change made in manifest
 
Upvote 0

ostau

Member
Licensed User
Longtime User
B4X:
SetActivityAttribute(main, android:windowSoftInputMode, adjustPan|stateHidden)
Sorry, forgot to add my manifest. It's already in. It was the first Thing I tried.

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:windowSoftInputMode, adjustPan|stateHidden)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")
'End of default text.
 
Upvote 0

ArminKH

Well-Known Member
Sorry, forgot to add my manifest. It's already in. It was the first Thing I tried.

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:windowSoftInputMode, adjustPan|stateHidden)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")
'End of default text.
your code is
B4X:
SetApplicationAttribute(android:windowSoftInputMode, adjustPan|stateHidden)
but my code is
B4X:
SetActivityAttribute(main, android:windowSoftInputMode, adjustPan|stateHidden)

from DOC this is an Activity Attribute
 
Upvote 0

ostau

Member
Licensed User
Longtime User
your code is
B4X:
SetApplicationAttribute(android:windowSoftInputMode, adjustPan|stateHidden)
but my code is
B4X:
SetActivityAttribute(main, android:windowSoftInputMode, adjustPan|stateHidden)

from DOC this is an Activity Attribute
Hallo ArminKH,
thank you. I tried both, but there's no difference. The height of the TextBox is Floating from 8 Lines to 1.5 lines.
As soon as I scroll to line 15, the TextBox collapses. I can then scroll up line by line and somewhen the TextBox.Top moves up and the TextBox Shows 8 lines.

Any other idea? Kind regards, Oskar
 
Upvote 0

ostau

Member
Licensed User
Longtime User
It will be easier to help if you upload the project (File - Export as zip).

Thank you, didn't know this.
Please find attached the project (EditTextProblem.zip). Your help is very appriciated!

Regards, Oskar
 

Attachments

  • EditTextProblem.zip
    6 KB · Views: 329
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
If the automatic handling doesn't work good enough then you need to do it manually:
B4X:
Sub Activity_Create(FirstTime As Boolean)

   p.Initialize("panel")
   
   l.Initialize("label")
   l.Text = "Labeltext"   
   p.AddView(l,0%x,60%y,30%x,40%y)
   
   e.Initialize("edittext1")
   e.Color = Colors.LightGray
   For i = 1 To 20
     e.Text = e.Text & i & Chr(10) & Chr(13)
   Next
   p.AddView(e,30%x,60%y,70%x,40%y)

   Activity.AddView(p,0,0,100%x, 100%y)
   IME.Initialize("ime")
   IME.AddHeightChangedEvent

End Sub

Sub ime_HeightChanged (NewHeight As Int, OldHeight As Int)
   e.Top = NewHeight - e.Height
End Sub

B4X:
SetActivityAttribute(main, android:windowSoftInputMode, adjustResize|stateHidden)
 
Upvote 0

ostau

Member
Licensed User
Longtime User
If the automatic handling doesn't work good enough then you need to do it manually:
B4X:
Sub Activity_Create(FirstTime As Boolean)

   p.Initialize("panel")
  
   l.Initialize("label")
   l.Text = "Labeltext"  
   p.AddView(l,0%x,60%y,30%x,40%y)
  
   e.Initialize("edittext1")
   e.Color = Colors.LightGray
   For i = 1 To 20
     e.Text = e.Text & i & Chr(10) & Chr(13)
   Next
   p.AddView(e,30%x,60%y,70%x,40%y)

   Activity.AddView(p,0,0,100%x, 100%y)
   IME.Initialize("ime")
   IME.AddHeightChangedEvent

End Sub

Sub ime_HeightChanged (NewHeight As Int, OldHeight As Int)
   e.Top = NewHeight - e.Height
End Sub

B4X:
SetActivityAttribute(main, android:windowSoftInputMode, adjustResize|stateHidden)

Hallo Erel,
nearly perfect! The TextBox now is always visible and has no longer a Floating height. Do you have a tip, how I can move the label up. Otherwise the user will not see, which field he Edits (if there are more than just one)?
Regards, Oskar
 
Upvote 0

ostau

Member
Licensed User
Longtime User
Hallo Erel,
nearly perfect! The TextBox now is always visible and has no longer a Floating height. Do you have a tip, how I can move the label up. Otherwise the user will not see, which field he Edits (if there are more than just one)?
Regards, Oskar

Do I have to add for each of my activities the SetActivityAttribute-line in the manifest or can I use a gerneral application Attribute, too?
Thanks, Oskar
 
Upvote 0

ostau

Member
Licensed User
Longtime User
Hallo Erel,
nearly perfect! The TextBox now is always visible and has no longer a Floating height. Do you have a tip, how I can move the label up. Otherwise the user will not see, which field he Edits (if there are more than just one)?
Regards, Oskar

Hallo Erel,

sorry, but there is realted issue now, I can't solve. I extended the sample by a second textbox. Now the following appears: when I click to textbox1, the textbox moves up as desired. Closing the keyborad - the textbox1 disappears. Clicking into the second textbox, the first textbox moves up and the keyborad overlays the second textbox with the cursor in it.
The reason is pretty clear, because I move up just edittext1 in the ime_HeightChanged-event.
But I didn't find any way, to decide, which of the both textboxes raised the event and which one should be moved?
And the second problem is, that the moved textbox will not be restored in it's original position after hiding the keyboard.
I attachted the modified project as zip.

Thanks in advance for your help.
 
Upvote 0

ostau

Member
Licensed User
Longtime User
Push the panel:
B4X:
Sub ime_HeightChanged (NewHeight As Int, OldHeight As Int)
  p.Top = NewHeight - p.Height
End Sub
Thank you, Erel.

I found for me the following cookbook (hope this helps others with the same problem):

Use Scrollviews, when ever it is possible.
Place EditText on Scrollview-Panel.
Move the Scrollview-Panel using IME.
That work in 99 of 100 cases.

Thanks again, kind regards, Oskar
 
Upvote 0
Top