У меня проблема, я не могу центрировать свой заголовок на панели инструментов (@ + id/toolbar_title). Я попытался установить RelativeLayout, используйте layout_gravity: center, но он не работает. Я добавил цвета, чтобы отличить макет, но я не могу публиковать фотографии.Название центра на ToolBar
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>
Вы знаете, что стандарт для панели инструментов выровнен по левому краю? Существует причина, по которой трудно делать то, что вы пытаетесь (что не для разработки стандартов) – Booger
Интересно, не хочу ли я использовать основной заголовок панели инструментов, который я не вижу? – GJer
Что значит, что вы этого не видите? https://developer.android.com/reference/android/widget/Toolbar.html#setTitle%28int%29 – Booger