How can I put a label inside an entry

I have an entry that defines as numeric, but I would like to have the unit "USD" inside it, a text that even erasing the typed numbers the text keeps.

It could use a placeholder, but when writing in entry the text disappears.

So how could I bind a label inside an entry?

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I think you can have a grid with 2 columns. in first column you can add the entry. In second column, the USD Label.
    You could also add the Enrty from column 1 to column 2 so the Label seems inside the entry

  • XazinXazin Member ✭✭

    You could do this using RelativeLayout, but it's quite a hassle.
    I believe maybe Xamarin has some CSS functionality, so you could probably do something with inline-block if you spend an hour or so looking up how CSS works and the simple CSS you'd need.

    My best alternative is to do as @AlessandroCaliaro said.
    You can make it so Entry goes from column1 to column2 or you could simply have USD besides the entry ...
    Since it's quite the same ... I understand the whole deal though since it would look better.

    Here I have a simple Grid that has an entry in column 1 and a label in column 2.

    The StackLayout is the main ContentPage. Just so you don't copy it along...

    <StackLayout>
            <Label Text="The below showcases a full width entry using RelativeLayout" />
    
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="1*" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
    
                <!-- Grid Here -->
                <Entry Text="" Placeholder="9.99" Grid.Row="0" Grid.Column="0" VerticalOptions="StartAndExpand"/>
                <Label Text="USD" FontAttributes="Bold" FontSize="18" TextColor="Green" Grid.Row="0" Grid.Column="1" HorizontalOptions="Center" VerticalOptions="Center" Margin="0, 0, 5, 0"/>
    
            </Grid>
    
            <Label Text="This is the end of page." />
    
        </StackLayout>
    

    Image below (I'm too new for links so yeah, that happened, awkward!)
    i.imgur.com /oHudYLp.png

    Goodluck my man....

Sign In or Register to comment.