Actionbar centered title with buttons

本秂侑毒 提交于 2019-12-05 17:49:57

You can try this in the TextView:

<TextView
    android:id="@+id/actionbar_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:maxHeight="1dp"
    android:maxLines="1"
    android:paddingLeft="48dp"
    android:paddingRight="48dp"
    android:text="Bacon ipsum"
    android:textColor="#777777"
    android:textSize="20sp" />
Risadinha
  1. Remove the launcher icon from your RelativeLayout.
  2. Change the width of the RelativeLayout to wrap_content
  3. Remove:

    actionBar.setDisplayShowCustomEnabled(true); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowTitleEnabled(false);

  4. Add:

    ActionBar.LayoutParams lp = new ActionBar.LayoutParams(
    
    ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.CENTER);
    
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM)
    actionBar.setCustomView(yourInflatedCustomView, lp);
    

Have you tried to implement to the text this code?

android:layout_centerHorizontal="true"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!