Android Question EditText - Justified Alignement

Discussion in 'Android Questions' started by js486dog, Sep 13, 2019.

  1. Erel

    Erel Administrator Staff Member Licensed User

    Do you only need to show text? If you are looking for an editable solution then it will not work.
     
  2. js486dog

    js486dog Member Licensed User

    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).
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    This is how justify alignment looks in BBCodeView:

    [​IMG]

    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:
    Code:
    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 and emexes like this.
  4. js486dog

    js486dog Member Licensed User

    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:

    Code:
    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(
    10dip10dip10dip10dip)
        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
     

    Attached Files:

    Erel likes this.
  5. Erel

    Erel Administrator Staff 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.
     
    js486dog likes this.
  6. js486dog

    js486dog Member Licensed User

    OK. Yes. Thank you very much Erel.
     
  7. js486dog

    js486dog Member Licensed User

    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.
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this question.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice