我知道有兩種設置活動標題的方法。一種方法是將它設置在Android清單中,像這樣android:label =「@ string/app_name」。其次,以編程方式設置活動類,如setTitle(「Hello World!」)。這兩種方式都位於左側,但我怎麼能把它放在中心?
回答
嘗試通過添加文本爭奪創建自定義標題W¯¯下喜歡你的活動這
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay">
<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>
通話工具欄
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_top);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
TextView mTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
mTitle.setText("any");
,那麼如何才能刪除默認應用程序名稱actionBar .. –
getSupportActionBar()。setDisplayShowTitleEnabled(false); –
你可以使用Hitesh方法回答下面的完美 –
使用工具欄
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/img_header">
<TextView
android:id="@+id/activity_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="TITLE"
android:layout_gravity="center"
android:textColor="@android:color/white"
android:textSize="@dimen/dim_20"
android:typeface="serif" />
</android.support.v7.widget.Toolbar>
集主題清單文件NotitleBar活動標籤內
android:theme="@android:style/Theme.Translucent.NoTitleBar"
或
setSupportActionBar(findViewById(R.id.toolbar));
那麼如何在動作條刪除默認應用程序名稱.. –
我編輯我的回答,請再次檢查 –
試試這個:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android Toolbar"
android:textColor="@android:color/white"
android:textSize="18sp"
android:textStyle="bold"
android:layout_gravity="center"
android:id="@+id/toolbar_title" />
</android.support.v7.widget.Toolbar>
在你Activity
:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
TextView mTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
mTitle.setText("Your Title");
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(""); // Hide default app name
- 1. 中心動作欄標題
- 2. 如何讓android動作條標題中心對齊?
- 3. 如何對齊操作欄標題在屏幕的中心,而不是操作欄的中心
- 4. 如何在Android上的動作欄中對齊中心項目
- 5. ionic2:標題標題不對齊中心
- 6. 如何中心對齊導航欄
- 7. Android中標題欄文本的中心對齊
- 8. 中心對齊分頁欄
- 9. 中心對齊鈦操作欄中的圖標爲Android
- 10. 使用android中的樣式中心對齊操作欄中的標題。
- 11. 中心對齊標題中的JFrame
- 12. 如何將徽標和標題對齊到頁面中心?
- 13. dhtmlxlyout標題文本對齊中心
- 14. [R GGPLOT2中心對齊多行標題
- 15. 網格視圖標題中心對齊
- 16. 將標題對齊到中心
- 17. 將DataGrid列標題對齊中心
- 18. 中心對齊離子標題
- 19. 如何在不使用自定義視圖的情況下將動作欄標題與中心對齊
- 20. 動作欄對齊按鈕
- 21. 安卓動作欄中的活動中心標題
- 22. 如何居中對齊Windows窗體中的標題欄文本?
- 23. UILabel中心對齊問題
- 24. PyQt5:中心對齊標籤
- 25. 如何製作中心對齊的窗口標題(wpf中的窗口)
- 26. 我該如何左對齊Xcode中導航欄的標題?
- 27. 如何對齊中心highcharts
- 28. 標題區div沒有中心對齊標題div
- 29. 表對齊中心不對齊中心
- 30. 標題欄位於中心
如果您使用的工具欄,然後用在谷歌texttitle appereance –
搜索。什麼你試過到目前爲止? –
的可能的複製[如何使Android操作欄,標題居中對齊?(http://stackoverflow.com/questions/21770428/how-to-make-android-action-bar-title-center-aligned) – Pehlaj