如何在 Android 的标题栏中隐藏应用程序名称?

How to hide app name from title bar in Android?

我的应用显示名称和图标。我想隐藏名字。

我该怎么做?

你必须打电话给`

getSupportActionBar().setDisplayShowTitleEnabled(false) - 隐藏它,

getSupportActionBar().setTitle("new title"); - 如果你想改变它

如果您想在代码之外执行此操作,请将其放入您的清单中:
<activity android:name=".ActivityName" android:theme="@android:style/Theme.NoTitleBar">

编辑:ranjith 先于我。

有点"workaround",但工作正常:

在清单中

<activity
        android:name=".YourActivity"
        android:label="" />

只需将 styles.xml 中 appTheme 样式的父级 属性 替换为 '@android:style/Theme.NoTitleBar'

您可以使用 getSupportActionBar。 如果您只想隐藏您的应用程序名称,请在该页面的 Activity 中使用此代码:

getSupportActionBar().setDisplayShowHomeEnabled(false);
   

如果你想隐藏 ActionBar 使用这个

getSupportActionBar().hide();

您可以通过以下方式重命名您的应用:

getSupportActionBar().setTitle("that name you want");

您总共可以使用:

getSupportActionBar().

和其他代码...

对我有用

转到 Style.xml 更改

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">

在 Kotlin 中你可以使用:

supportActionBar?.setDisplayShowTitleEnabled(false)

“?”这很重要,因为您可能已经禁用了整个标题栏,因为您尝试将一个不存在的标题栏的标题状态设置为 false。