Android toolbar always centered title with icons -


i want center title in toolbar. have 4 cases achieve, title should centered :

[<       short        ] [< loooong_titleeee...] [        short        ]  [        short       +] 

below custom toolbar layout. 3 cases perfectly, second 1 not, it's cover button. how should change layout solve it? tried many castlings in layout, every time wrong :)

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent">  <android.support.v7.widget.toolbar     android:id="@+id/toolbar"     android:layout_width="match_parent"     android:layout_height="?attr/actionbarsize"     android:background="@color/iosbackgroundgray"     android:contentinsetend="0dp"     android:contentinsetleft="0dp"     android:contentinsetright="0dp"     android:contentinsetstart="0dp"     app:contentinsetend="0dp"     app:contentinsetleft="0dp"     app:contentinsetright="0dp"     app:contentinsetstart="0dp">      <relativelayout         android:id="@+id/root_layout"         android:layout_width="match_parent"         android:layout_height="match_parent">          <linearlayout             android:id="@+id/left_buttons"             android:layout_width="wrap_content"             android:layout_height="match_parent"             android:layout_alignparentleft="true"             android:layout_marginleft="10dp"             android:gravity="center">              <textview                 android:id="@+id/left_text_button"                 android:layout_width="wrap_content"                 android:layout_height="match_parent"                 android:layout_gravity="start"                 android:gravity="center"                 android:textcolor="@android:color/holo_blue_dark"                 android:textsize="20sp"                 android:visibility="gone" />              <imagebutton                 android:id="@+id/back_button"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:background="@android:color/transparent"                 android:padding="10dp"                 android:src="@drawable/ic_arrow_back_black_24dp"                 android:visibility="gone" />         </linearlayout>          <textview             android:id="@+id/toolbar_title"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_centerinparent="true"             android:ellipsize="end"             android:maxlines="1"             android:textsize="20sp"             android:textstyle="bold"             android:visibility="gone" />          <linearlayout             android:id="@+id/right_buttons"             android:layout_width="wrap_content"             android:layout_height="match_parent"             android:layout_alignparentright="true"             android:layout_gravity="end"             android:layout_marginright="10dp">              <textview                 android:id="@+id/right_text_button"                 android:layout_width="wrap_content"                 android:layout_height="match_parent"                 android:enabled="false"                 android:gravity="center"                 android:textsize="20sp"                 android:textstyle="bold"                 android:visibility="gone" />              <imagebutton                 android:id="@+id/add_button"                 android:layout_width="wrap_content"                 android:layout_height="match_parent"                 android:background="@android:color/transparent"                 android:paddingbottom="15dp"                 android:paddingleft="15dp"                 android:paddingtop="15dp"                 android:src="@drawable/ic_add_black_36dp"                 android:tint="@android:color/holo_blue_dark"                 android:visibility="gone" />         </linearlayout>          <view             android:layout_width="match_parent"             android:layout_height="1dp"             android:layout_alignparentbottom="true"             android:background="@color/iosdarkgray" />     </relativelayout> </android.support.v7.widget.toolbar> 

change textview of title follow:

<textview    android:id="@+id/toolbar_title"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_centerinparent="true"    android:ellipsize="end"    android:maxlines="1"    android:textsize="20sp"    android:textstyle="bold"    android:visibility="gone"    android:layout_toendof="@id/left_buttons"    android:layout_tostartof="@+id/right_buttons" /> 

and rightbuttons layout follow:

<linearlayout    android:id="@id/right_buttons"    android:layout_width="wrap_content"    android:layout_height="match_parent"    android:layout_alignparentright="true"    android:layout_gravity="end"    android:layout_marginright="10dp"> 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -