panagulis72
panagulis72

Reputation: 2169

Remote image on NavigationButton in Nativescript/Angular

I want to put the user's avatar on the left of my app's header. It works fine in IOS, but it doesn't work in android. I tried to do this:

    <NavigationButton [icon]="customImage" color="#a81b38" (tap)="toggleSideDrawer()" *ngIf="isAndroid">
        <StackLayout verticalAlignment="center">
            <Label id="avatarImg" height="45" width="45" borderRadius="50" backgroundColor="#eeeeee"></Label>
        </StackLayout>
    </NavigationButton>

but I get an error during compilation. The custom image is a remote image (https://myimage), but android is looking into local file resources.

So I removed the icon and I put the image inside, trying this:

 <NavigationButton color="#a81b38" (tap)="toggleSideDrawer()" *ngIf="isAndroid">
    <StackLayout verticalAlignment="center">
        <Label [style.background-image]="customImage" style.background-position="center"
            style.background-size="cover" class="avatarImage" height="30" width="30" borderRadius="50"
            backgroundColor="#eeeeee"></Label>
    </StackLayout>
</NavigationButton>

I don't get any error, but I can't see anything in my header, it's all white. I tried also to use instead of , but same issue

Upvotes: 1

Views: 307

Answers (1)

William Juan
William Juan

Reputation: 1415

You can try removing the <NavigationButton> for android and putting the <StackLayout> directly inside your <ActionBar> with a horizontalAlignment set to 'left'

<ActionBar>
  <StackLayout *ngIf="isAndroid" horizontalAlignment="left" verticalAlignment="center">
    <Label [style.background-image]="customImage" style.background-position="center"
            style.background-size="cover" class="avatarImage" height="30" width="30" borderRadius="50"
            backgroundColor="#eeeeee"></Label>
  </StackLayout>
</ActionBar>

Upvotes: 1

Related Questions