设置标题重心在ActionBarSherlock中心 [英] Set Title gravity to center in ActionBarSherlock
问题描述
您好我想申请一个自定义Backgroundlayout只是我的主要活动。我无法找到一个解决方案。有人可以给我一些建议吗?
Hello I would like to apply a custom Backgroundlayout just for my Main Activity. I couldn't find a solution. Can somebody give me some tips?
想只是一个简单的TextView与在动作条背景。这可能吗?
would like to have just a simple TextView with a background in the Actionbar. Is this possible?
我设法删除图标,并设置和backgroundImage。但我怎么可以设置文字的重力中心,并改变typefont?
I managed to remove the icon and set a backgroundimage. But how can I set the gravity of the text to center and change the typefont?
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(myimage));
这应该是这样的:
It should look like this:
谢谢!
推荐答案
您必须设置一个自定义布局的动作条是这样的:
You have to set a custom layout for the Actionbar like this:
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.yourlayout);
在你的布局,你可以再添加一个TextView,并设置其重力中心
。例如:
In your layout you can then add a TextView and set its gravity to center
. E.g.:
<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您的活动里面是这样的:
Then you can set your custom typefont inside your Activity from your assets like this:
TextView txt = (TextView) findViewById(R.id.mytext);
Typeface font = Typeface.createFromAsset(getAssets(), "yourfont.ttf");
txt.setTypeface(font);
这篇关于设置标题重心在ActionBarSherlock中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!