簡體   English   中英

如何在 Android(使用 Nativescript)中將 ActionBar 標題文本居中?

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

我想居中對齊操作欄文本

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

為我解決了。

解決方案

為了更清楚地指出這一點,我在這個答案中寫了 Meggan Naude 的解決方案。 在問題提要中回答您自己的問題還不夠明顯。

不使用ActionBar標簽的title屬性,而是使用Label作為單獨的內部標簽,如下所示:

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

並在css設置標題樣式:

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

同樣,這個答案歸功於提問者本身。 干杯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM