簡體   English   中英

如何將動作條標題對齊到android中的中心?

[英]how to align actionbar title to center in android?

我已經使用了此代碼,它對於單個活動也可以正常工作,但是在我的應用程序中,我有許多需要不同標題的活動。 我可能需要為每個活動創建單獨的布局文件,還是有其他方法?

getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
getSupportActionBar().setCustomView(R.layout.actionbar);

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">

<TextView
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_gravity="center"
 android:text="YOUR ACTIVITY TITLE"
 android:textColor="#ffffff"
 android:textSize="24sp" />
 </LinearLayout>
// Try This 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">

<TextView
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="YOUR ACTIVITY TITLE"
 android:textColor="#ffffff"
 android:textSize="24sp" />
 </LinearLayout>

暫無
暫無

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

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