[英]How to align action bar title in center of screen, not the center of action bar
[英]How to align action bar title in center of screen in fragment?
我的操作欄有菜單,僅在片段中設置標題。
無法對准中心。
我能做什么? 默認情況下,它僅顯示左側。 如何在片段標題的操作欄上的CENTER位置對齊?
您必須使用工具欄。
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_top"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="@color/action_bar_bkgnd"
app:theme="@style/ToolBarTheme" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toolbar Title"
android:layout_gravity="center"
android:id="@+id/toolbar_title" />
</android.support.v7.widget.Toolbar>
這意味着您可以根據需要設置TextView的樣式,因為它只是常規的TextView。 因此,在您的活動中,您可以像這樣訪問標題:
Toolbar toolbarTop = (Toolbar) findViewById(R.id.toolbar_top);
TextView mTitle = (TextView) toolbarTop.findViewById(R.id.toolbar_title);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.