首页 > 解决方案 > 无法在 Android 应用程序中看到应用程序名称

问题描述

我没有在操作栏中获得我的应用程序名称。

所以请帮助我了解它被隐藏的原因以及如何解决这个问题。

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   >

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


            android:id="@+id/my_Toolbar"
            layout="@layout/my_toolbar"

        <com.google.android.material.tabs.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.viewpager.widget.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/appBarLayout"/>

</RelativeLayout>

标签: androidandroid-studioandroid-layoutmenuandroid-actionbar

解决方案


在清单文件中在相应的活动处添加标签,例如:

 <activity
        android:name=".MainActivity"
        android:label="app_name"

您还可以在活动中以编程方式设置标题:

  getSupportActionBar().setTitle("My app name");

推荐阅读