【问题标题】:How to align action bar title in center of screen, not the center of action bar如何在屏幕中心对齐操作栏标题,而不是操作栏的中心
【发布时间】:2014-12-29 17:51:54
【问题描述】:

我使用这种方法将操作栏标题居中对齐

How to make android action bar title center aligned?

但我的操作栏有菜单,然后操作栏宽度与屏幕不一样

所以标题不完全是中心。

还有其他方法可以使标题居中吗?


代码:

actionbar.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="YOUR ACTIVITY TITLE"
        android:textColor="#000"
        android:textSize="24sp" />
</LinearLayout>


the activity which used custom action bar

public class WriteText extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_write_text);

        getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
        getActionBar().setCustomView(R.layout.actionbar);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.write_tag, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

【问题讨论】:

    标签: android android-actionbar


    【解决方案1】:

    也许您可以更改操作栏 xml 文件以制作您自己风格的操作栏。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-15
      • 2018-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-05
      • 1970-01-01
      • 2013-11-22
      相关资源
      最近更新 更多