Le titre de ma barre d'outils ne s'affiche pas.
Voici mon 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"/>
Je ne fais pas référence à la barre d’outils dans mon code java, mais je peux vous montrer que si vous en avez besoin. Il semble que je devrais pouvoir définir le titre de la barre d’outils simplement en utilisant android:title="desired_title"
. La barre d’outils est affichée. La couleur et la taille sont correctes, mais le titre ne s’affiche pas.
Réponses:
1 pour la réponse № 1Utilisez le suivant.
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_main);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Title");