Android Question EditText - Justified Alignement

js486dog

Active Member
Licensed User
Do you only need to show text? If you are looking for an editable solution then it will not work.
Thank you for the answer Erel.
Yes Erel.

I need only show text for reading.
I do not need edit it.

*I need load text from txt file - I have solved it with BBCodeView .
*I need only justify alignement of showing text - I can not do that with BBCodeView .
*I need change size, color of showing text programaticaly - I can not do that with BBCodeView.
*I need to change background color, border color and border width and corner radius of BBCodeView programaticaly - I can not do that with BBCodeView.

EditText with Input Type = NONE is very good for my purpose, but there is not justify alignement(only left, right, center).
 

Erel

Administrator
Staff member
Licensed User
This is how justify alignment looks in BBCodeView:



I need only justify alignement of showing text - I can not do that with BBCodeView .
Set the alignment property to justify.

I need change size, color of showing text programaticaly - I can not do that with BBCodeView.
Go over the example. It demonstrates all of this.

I need to change background color, border color and border width and corner radius of BBCodeView programaticaly - I can not do that with BBCodeView.
Put BBCodeView in a panel and set the panel's border.


Example code:
B4X:
BBCodeView1.Padding.Right = BBCodeView1.Padding.Right + 5dip
   BBCodeView1.Text =  _
$"
[Alignment=justify]Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit amet augue sit amet purus laoreet varius. Quisque quis odio accumsan, cursus diam ac, accumsan nibh. Phasellus placerat enim quis dolor imperdiet, eu ullamcorper sem interdum. Sed in massa lorem. Aliquam auctor auctor lacus, et fringilla nisi cursus volutpat. Etiam egestas pharetra erat, in elementum est suscipit id. Aenean sed lectus risus. [/alignment]

[Alignment=justify]Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit amet augue sit amet purus laoreet varius. Quisque quis odio accumsan, cursus diam ac, accumsan nibh. Phasellus placerat enim quis dolor imperdiet, eu ullamcorper sem interdum. Sed in massa lorem. Aliquam auctor auctor lacus, et fringilla nisi cursus volutpat. Etiam egestas pharetra erat, in elementum est suscipit id. Aenean sed lectus risus. [/alignment]

[Alignment=justify]Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit amet augue sit amet purus laoreet varius. Quisque quis odio accumsan, cursus diam ac, accumsan nibh. Phasellus placerat enim quis dolor imperdiet, eu ullamcorper sem interdum. Sed in massa lorem. Aliquam auctor auctor lacus, et fringilla nisi cursus volutpat. Etiam egestas pharetra erat, in elementum est suscipit id. Aenean sed lectus risus. [/alignment]
"$
Update to BCTextEngine v1.62.
 

js486dog

Active Member
Licensed User
This is how justify alignment looks in BBCodeView:




Set the alignment property to justify.


Go over the example. It demonstrates all of this.


Put BBCodeView in a panel and set the panel's border.


Example code:
B4X:
BBCodeView1.Padding.Right = BBCodeView1.Padding.Right + 5dip
   BBCodeView1.Text =  _
$"
[Alignment=justify]Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit amet augue sit amet purus laoreet varius. Quisque quis odio accumsan, cursus diam ac, accumsan nibh. Phasellus placerat enim quis dolor imperdiet, eu ullamcorper sem interdum. Sed in massa lorem. Aliquam auctor auctor lacus, et fringilla nisi cursus volutpat. Etiam egestas pharetra erat, in elementum est suscipit id. Aenean sed lectus risus. [/alignment]

[Alignment=justify]Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit amet augue sit amet purus laoreet varius. Quisque quis odio accumsan, cursus diam ac, accumsan nibh. Phasellus placerat enim quis dolor imperdiet, eu ullamcorper sem interdum. Sed in massa lorem. Aliquam auctor auctor lacus, et fringilla nisi cursus volutpat. Etiam egestas pharetra erat, in elementum est suscipit id. Aenean sed lectus risus. [/alignment]

[Alignment=justify]Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit amet augue sit amet purus laoreet varius. Quisque quis odio accumsan, cursus diam ac, accumsan nibh. Phasellus placerat enim quis dolor imperdiet, eu ullamcorper sem interdum. Sed in massa lorem. Aliquam auctor auctor lacus, et fringilla nisi cursus volutpat. Etiam egestas pharetra erat, in elementum est suscipit id. Aenean sed lectus risus. [/alignment]
"$
Update to BCTextEngine v1.62.
Thank you Erel it works fine.

I think BBCodeView is the best way to change the EditText if I want text justification.
For background color and border we need to put BBCodeView in a panel and set the panel's border.

Here is the Code and zip file:

B4X:
Sub Globals
    Private MyView As BBCodeView
    Private TextEngine As BCTextEngine
    Private MyText As String
    Dim txtsize As Int
    Dim alig, texcolor As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")
    TextEngine.Initialize(Activity)
    MyText = File.ReadString(File.DirAssets, "from.txt")
    MyView.Padding.Initialize(10dip, 10dip, 10dip, 10dip)
    txtsize = 16
    alig = "justify"
    texcolor = "#0000FF"
    MyView.Text = $" [Alignment=${alig}][TextSize=${txtsize}][color=${texcolor}]${MyText}[/color][/TextSize][/alignment] "$
End Sub

Sub JustifyButton_Click
    alig = "justify"
    MyView.Text = $" [Alignment=${alig}][TextSize=${txtsize}][color=${texcolor}]${MyText}[/color][/TextSize][/alignment] "$
End Sub

Sub RaggedButton_Click
    alig = "left"
    MyView.Text = $" [Alignment=${alig}][TextSize=${txtsize}][color=${texcolor}]${MyText}[/color][/TextSize][/alignment] "$
End Sub

Sub SmallButton_Click
    txtsize = 10
    MyView.Text = $" [Alignment=${alig}][TextSize=${txtsize}][color=${texcolor}]${MyText}[/color][/TextSize][/alignment] "$
End Sub

Sub MediumButton_Click
    txtsize = 16
    MyView.Text = $" [Alignment=${alig}][TextSize=${txtsize}][color=${texcolor}]${MyText}[/color][/TextSize][/alignment] "$
End Sub

Sub LargeButton_Click
    txtsize = 22
    MyView.Text = $" [Alignment=${alig}][TextSize=${txtsize}][color=${texcolor}]${MyText}[/color][/TextSize][/alignment] "$
End Sub
 

Attachments

js486dog

Active Member
Licensed User
You shouldn't repeat the same code multiple times. Move it to another sub and call this sub. txtsize and alig should probably don't need to be global variables.
Erel please,
how can I jump on the start of the text programmatically ?
I am scrolling and I am in the middle of the text - I click on button to jump on the beginning of text.
 
Top