简体   繁体   English

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

[英]How do I center ActionBar title text in Android (with Nativescript)?

I want to center align the actionbar text我想居中对齐操作栏文本

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

in NativeScript.在 NativeScript 中。 Currently the above renders with the title left aligned.目前,上面呈现的标题左对齐。 I tried adding a class and adding text-align: center;我尝试添加一个类并添加text-align: center; but that did not work.但这没有用。 In iOS it seems to automatically align this text center judging by the images in the NativeScript docs.在 iOS 中,它似乎根据 NativeScript 文档中的图像自动对齐此文本中心。

Solution in case anyone else ever needs it: Instead of using the title attribute of the ActionBar tag, use Label as a seperate internal tag as follows:万一其他人需要它的解决方案:不要使用 ActionBar 标记的 title 属性,而是使用 Label 作为单独的内部标记,如下所示:

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

and style the title in css:并在 css 中设置标题样式:

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

Solved it for me.为我解决了。

SOLUTION解决方案

To point it out more clearly I write Meggan Naude's solution in this answer.为了更清楚地指出这一点,我在这个答案中写了 Meggan Naude 的解决方案。 Answering your own question in the question feed isn't obvious enough.在问题提要中回答您自己的问题还不够明显。

Instead of using the title attribute of the ActionBar tag, use Label as a seperate internal tag as follows:不使用ActionBar标签的title属性,而是使用Label作为单独的内部标签,如下所示:

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

and style the title in css :并在css设置标题样式:

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

Again, this answer is credited to the question asker itself.同样,这个答案归功于提问者本身。 Cheers干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM