i have problem, can't center title in toolbar (@+id/toolbar_title). tried put relativelayout, use layout_gravity: center doesn't work. have added colors distinguish layout can't post pictures yet.
activity_main.xml
<android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" tools:context=".mainactivity" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <relativelayout android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="60dp" android:background="@android:color/holo_green_dark" app:theme="@style/toolbartheme" app:popuptheme="@style/theme.appcompat" android:layout_gravity="center_vertical" > <textview android:id="@+id/toolbar_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centervertical="true" android:layout_gravity="center" android:background="@color/primarydark" android:textsize="20dp" /> <relativelayout android:layout_width="wrap_content" android:layout_height="match_parent" android:background="@color/primary"> <imagebutton android:id="@+id/show_list_actualites" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_fleche_bas" android:adjustviewbounds="true" android:layout_toleftof="@+id/loupe" android:layout_marginleft="20dp" android:layout_marginright="15dp" android:layout_centervertical="true" android:padding="15dp" android:background="@color/primarydark" /> <!--android:background="@android:color/transparent"--> <imageview android:id="@+id/loupe" android:layout_width="wrap_content" android:layout_height="12dip" android:src="@drawable/ic_rech" android:rotation="270" android:adjustviewbounds="true" android:layout_centervertical="true" android:layout_alignparentright="true" android:layout_marginright="20dp" android:background="@color/primarydark" /> </relativelayout> </android.support.v7.widget.toolbar> </relativelayout> <relativelayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent"> <framelayout android:id="@+id/content_fragment" android:layout_width="match_parent" android:layout_height="match_parent"/> <linearlayout android:id="@+id/slide_news_list" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:visibility="gone"> <listview android:id="@+id/list_slider_news_menu" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/action_bar_background" android:text="item 1"/> <button android:id="@+id/close_news_slide" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/grey_tranparent"/> </linearlayout> </relativelayout> </linearlayout> <listview android:id="@+id/left_drawer" android:background="@android:color/white" android:layout_width="305dp" android:layout_height="match_parent" android:layout_gravity="start"/> </android.support.v4.widget.drawerlayout>
styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="theme.appcompat.light.noactionbar" parent="@style/theme.appcompat.light"> <item name="android:windownotitle">true</item> <item name="windowactionbar">false</item> </style> <style name="apptheme.base" parent="theme.appcompat.light.noactionbar"> <item name="colorprimary">@color/primary</item> <item name="colorprimarydark">@color/primarydark</item> </style> <style name="apptheme" parent="apptheme.base"> </style> <style name="toolbartheme" parent="theme.appcompat"> <item name="android:windownotitle">true</item> <item name="android:textcolorprimary">@color/action_bar_text</item> <item name="actionmenutextcolor">@color/action_bar_text</item> <item name="android:textcolorsecondary">@color/action_bar_text</item> <item name="android:layout_gravity">center_horizontal</item> </style> </resources>
centering text in toolbar against android design standards. think why having issues accomplishing this. not try adjust text alignment, insure app fits within android ecosystem.
check link details on toolbar design standards: http://www.google.com/design/spec/layout/structure.html#structure-toolbars
i not answering how asking, suggesting don't in first place (use standard format, , easier you).
Comments
Post a Comment