[英]Set Title gravity to center in ActionBarSherlock
您好我想為我的主要活動應用自定義Backgroundlayout。 我找不到解決方案。 有人可以給我一些提示嗎?
想在Actionbar中只有一個帶背景的簡單TextView。 這可能嗎?
我設法刪除圖標並設置backgroundimage。 但是,如何將文本的重力設置為居中並更改typefont?
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(myimage));
它應該如下所示:
謝謝!
您必須為Actionbar設置自定義布局,如下所示:
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.yourlayout);
在您的布局中,您可以添加TextView並將其重力設置為center
。 例如:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Header!"
android:id="@+id/mytext"
android:textColor="#ffffff"
android:textSize="25dp" />
</LinearLayout>
然后,您可以在資源中設置自定義typefont,如下所示:
TextView txt = (TextView) findViewById(R.id.mytext);
Typeface font = Typeface.createFromAsset(getAssets(), "yourfont.ttf");
txt.setTypeface(font);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.