如何在 Android 中将 ActionBar 标题文本居中(使用 Nativescript)?

问题描述 投票:0回答:2

我想居中对齐操作栏文本

<ActionBar class="text-center" [title]="title" (loaded)="onLoadedActionBar()"></ActionBar>

在 NativeScript 中。目前,上面的渲染标题左对齐。我尝试添加一个类并添加

text-align: center;
但这不起作用。 在 iOS 中,根据 NativeScript 文档中的图像判断,它似乎会自动对齐该文本中心。

解决方案以防其他人需要它: 不要使用 ActionBar 标签的 title 属性,而是使用 Label 作为单独的内部标签,如下所示:

<ActionBar (loaded)="onLoadedActionBar()">
  <Label class="title" [text]="title"></Label>
</ActionBar>

并在 css 中设置标题样式:

.title {
  font-weight: bold;
  font-size: 17px;
}

帮我解决了。

android nativescript
2个回答
0
投票

解决方案

为了更清楚地指出这一点,我在这个答案中写下了 Meggan Naude 的解决方案。 在问题提要中回答您自己的问题还不够明显。

不要使用

title
标签的
ActionBar
属性,而是使用
Label
作为单独的内部标签,如下所示:

<ActionBar (loaded)="onLoadedActionBar()">
  <Label class="title" [text]="title"></Label>
</ActionBar>

并在

css
:

中设置标题样式
.title {
  font-weight: bold;
  font-size: 17px;
}

再次强调,这个答案归功于提问者本人。干杯


0
投票

解决方案

为了更清楚地指出这一点,我在这个答案中写下了 Meggan Naude 的解决方案。在问题提要中回答您自己的问题还不够明显。

不要使用 ActionBar 标签的 title 属性,而是使用 Label 作为单独的内部标签,如下所示:

<ActionBar (loaded)="onLoadedActionBar()">
  <Label class="title" [text]="title"></Label>
</ActionBar>

并在 css 中设置标题样式:

.title {
  font-weight: bold;
  font-size: 17px;
}

再次强调,这个答案归功于提问者本人。干杯

© www.soinside.com 2019 - 2024. All rights reserved.