[英]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.