Android 在ActionBarSherlock中将标题重心设置为中心
您好,我想为我的主要活动应用自定义背景布局。我找不到解决办法。谁能给我一些提示吗 只希望在Actionbar中有一个背景的简单文本视图。这可能吗 我设法删除了图标并设置了背景图像。但是我如何将文本的重心设置为中心并更改字体呢Android 在ActionBarSherlock中将标题重心设置为中心,android,android-actionbar,actionbarsherlock,android-theme,Android,Android Actionbar,Actionbarsherlock,Android Theme,您好,我想为我的主要活动应用自定义背景布局。我找不到解决办法。谁能给我一些提示吗 只希望在Actionbar中有一个背景的简单文本视图。这可能吗 我设法删除了图标并设置了背景图像。但是我如何将文本的重心设置为中心并更改字体呢 getSupportActionBar().setDisplayShowHomeEnabled(false); getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(myimag
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(myimage));
应该是这样的:
谢谢 您必须为Actionbar设置自定义布局,如下所示:
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.yourlayout);
TextView txt = (TextView) findViewById(R.id.mytext);
Typeface font = Typeface.createFromAsset(getAssets(), "yourfont.ttf");
txt.setTypeface(font);
在布局中,您可以添加一个文本视图,并将其重心设置为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>
如果你有任何标签,这是可怕的错误。选项卡保留,但标题位于htem下方