/ / Чому в моєму шоу "Панель інструментів" не заголовок? - android, android-layout, android-xml, android-toolbar

Чому не відображаються заголовки на панелі інструментів? - Android, андроїд-макет, android-xml, панель інструментів Android

Заголовок на моїй панелі інструментів не відображається.

Ось мій xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.mddri_.myeats.main._MainActivity">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="@color/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:title="@string/app_label"
android:titleTextColor="@color/textColor"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
android:layout_below="@+id/toolbar_main"
android:background="@color/colorPrimary"
/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/tab_layout"/>

Я не посилаюсь на панель інструментів у своєму коді Java, але можу показати вам, що якщо вам це потрібно. Схоже, я маю змогу встановити заголовок панелі інструментів просто за допомогою android:title="desired_title". На панелі інструментів відображається правильний колір і розмір, але заголовок не відображається.

Відповіді:

1 для відповіді № 1

Скористайтеся наступним.

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_main);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Title");