将标题重力设置为ActionBarSherlock中心

9 android android-theme actionbarsherlock android-actionbar

您好我想为我的主要活动应用自定义Backgroundlayout.我找不到解决方案.有人可以给我一些提示吗?

想在Actionbar中只有一个带背景的简单TextView.这可能吗?

我设法删除图标并设置backgroundimage.但是,如何将文本的重力设置为居中并更改typefont?

getSupportActionBar().setDisplayShowHomeEnabled(false);
    getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(myimage)); 
Run Code Online (Sandbox Code Playgroud)

它应该如下所示: 在此输入图像描述

谢谢!

Ahm*_*mad 16

您必须为Actionbar设置自定义布局,如下所示:

getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
getSupportActionBar().setCustomView(R.layout.yourlayout);
Run Code Online (Sandbox Code Playgroud)

在您的布局中,您可以添加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>
Run Code Online (Sandbox Code Playgroud)

然后,您可以在资源中设置自定义typefont,如下所示:

 TextView txt = (TextView) findViewById(R.id.mytext);  
 Typeface font = Typeface.createFromAsset(getAssets(), "yourfont.ttf");  
 txt.setTypeface(font);  
Run Code Online (Sandbox Code Playgroud)

  • 如果你有任何标签,这可怕的错误.标签保留,但标题是BENEATH htem (3认同)