android操作栏中活动的中心标题

android操作栏中活动的中心标题,android,android-layout,android-actionbar,statusbar,Android,Android Layout,Android Actionbar,Statusbar,现在,我的活动的标题显示在左侧为

现在,我的活动的标题显示在左侧为
,然后另一个菜单项显示在右侧。我想把我的标题放在中间,省去
这个主题不是android:style,而是style。将您的清单更改为此

    <activity
        android:name="com.company.YesterdayActivity"
        android:theme="@style/CustomTheme" >
    </activity>

编辑: 也许这是你父母的主题。你以前的主题是什么?尝试如下更改您的父主题:

    <style name="CustomWindowTitleBackground">
        <item name="android:background">#323331</item>
    </style>

    <style name="CustomTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:windowTitleSize">65dip</item>
        <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
    </style>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textViewActionBarTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Your Title" />

</LinearLayout>

#323331
65度
@样式/自定义窗口标题背景

只需在活动中为actionbar使用自定义视图即可

ActionBar actionBar = getSupportActionBar();
actionBar.setCustomView(R.layout.actionbar_layout);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setDisplayHomeAsUpEnabled(false); // Remove '<' next to home icon.
ActionBar ActionBar=getSupportActionBar();
actionBar.setCustomView(R.layout.actionBar\u布局);
actionBar.setDisplayOptions(actionBar.DISPLAY\u SHOW\u CUSTOM、actionBar.DISPLAY\u SHOW\u CUSTOM);

actionBar.setDisplayHomeAsUpEnabled(false);//删除“我还使用了actionbar sherlock,并通过此方法设置标题位置。您可以设置自定义文本视图并将其重心设置为中心。用下面的方法告诉我

    private void setHeader(){
    LayoutInflater linflater = (LayoutInflater)MainAccountActivity.context.getSystemService(MainAccountActivity.context.LAYOUT_INFLATER_SERVICE);
    View GalleryTitleView = linflater.inflate(R.layout.layout_header, null);

    galleryTitleTv = (TextView) GalleryTitleView
            .findViewById(R.id.GalleryTitleTv);
    galleryTitleTv.setText(ITWAppUIConstants.TAB_AGENDA);

    ActionBar.LayoutParams lp = new ActionBar.LayoutParams(
            ActionBar.LayoutParams.FILL_PARENT,
            ActionBar.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
    GalleryTitleView.setLayoutParams(lp);
    getSupportActionBar().setCustomView(GalleryTitleView);
  }
这是我使用的布局:

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:gravity="center"
android:orientation="vertical" >

<TextView
    android:id="@+id/GalleryTitleTv"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:paddingLeft="10dip"
    android:textColor="@color/white"
    android:textSize="20dip"
    android:textStyle="bold" />


研究如何为
操作栏
扩展自定义布局。我试过了。它说不能将自定义与其他功能混合使用。
android.util.AndroidRuntimeException:您不能将自定义标题与其他标题功能组合使用
如何关闭该功能?您可以在此处发布自定义样式xml吗?@user2045570我发布样式您知道如何使主题不影响该xml/活动中的所有内容吗?现在我对孩子的看法都不一样了。例如,我的EditText更高。自定义主题会扭曲布局的其余部分。如果我将其从清单移动到特定的自定义布局,它甚至不会生效。它崩溃了:无法将自定义与其他功能结合起来。在你实例化了actionBar之后?是的。注意:我不得不使用
getActionBar()
而不是
getSupportActionBar()
@CoteMounyo老实说,我不记得为什么我把那一行留在那里了。把它拿走。标题仍将存在于自定义布局中。只需在文本视图中设置它。但使用非支持ActionBar可能存在争议。不知道为什么…另外,您需要设置DisplayOptions,以便它知道如何使用自定义视图。。。我刚刚编辑了原稿。
    <style name="CustomWindowTitleBackground">
        <item name="android:background">#323331</item>
    </style>

    <style name="CustomTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:windowTitleSize">65dip</item>
        <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
    </style>
ActionBar actionBar = getSupportActionBar();
actionBar.setCustomView(R.layout.actionbar_layout);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setDisplayHomeAsUpEnabled(false); // Remove '<' next to home icon.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textViewActionBarTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Your Title" />

</LinearLayout>
    private void setHeader(){
    LayoutInflater linflater = (LayoutInflater)MainAccountActivity.context.getSystemService(MainAccountActivity.context.LAYOUT_INFLATER_SERVICE);
    View GalleryTitleView = linflater.inflate(R.layout.layout_header, null);

    galleryTitleTv = (TextView) GalleryTitleView
            .findViewById(R.id.GalleryTitleTv);
    galleryTitleTv.setText(ITWAppUIConstants.TAB_AGENDA);

    ActionBar.LayoutParams lp = new ActionBar.LayoutParams(
            ActionBar.LayoutParams.FILL_PARENT,
            ActionBar.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
    GalleryTitleView.setLayoutParams(lp);
    getSupportActionBar().setCustomView(GalleryTitleView);
  }
  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:gravity="center"
android:orientation="vertical" >

<TextView
    android:id="@+id/GalleryTitleTv"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:paddingLeft="10dip"
    android:textColor="@color/white"
    android:textSize="20dip"
    android:textStyle="bold" />