导航按钮在Nativescript / Angular中的远程图像

时间:2019-06-26 13:07:35

标签: android angular nativescript nativescript-angular

我想将用户的头像放在应用标题的左侧。它在IOS中工作正常,但在android中不工作。我尝试这样做:

    <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>

但是在编译过程中出现错误。自定义图片是远程图片(https://myimage),但是android正在调查本地文件资源。

所以我删除了图标,然后将图像放入其中,尝试这样做:

 <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>

我没有收到任何错误,但是我在标题中看不到任何内容,全为白色。我也尝试使用代替,但是同样的问题

1 个答案:

答案 0 :(得分:0)

您可以尝试删除Android的<NavigationButton>并将<StackLayout>直接放在<ActionBar>内,并将horizontalAlignment设置为'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>
相关问题