android - 没有图标但有标题的工具栏

标签 android android-actionbar android-toolbar

我想要一个没有图标的工具栏(并且在左边框和标题之间没有空白),但标题如下面的屏幕所示:

enter image description here

尝试了 ActionBar/Toolbar 方法的不同组合,但无法实现。我得到的是:

enter image description here

有什么方法可以在不定义自定义 Toolbar 的情况下实现第一个屏幕上的内容(我想将 Toolbar 视为 ActionBar 以具有 菜单项)?

我的themes.xml

<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="windowActionModeOverlay">true</item>

最佳答案

你可以试试:

final Toolbar mToolbar = (Toolbar)findViewById(R.id.toolbar);
mToolbar.setTitle(R.string.YOUR_TITLE);
setSupportActionBar(mToolbar);

并在 style.xml 中的 App 主题中,添加:

<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>

关于android - 没有图标但有标题的工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30125159/

相关文章:

java - 如何解决此 java.lang.UnsupportedOperationException : This is not supported in Android L?

android - 无法从工具栏菜单项android打开NavigationDrawer

android - 使用自定义工具栏未调用 onCreateOptionsMenu

android - 修改.mk文件时如何让NDK编译更多 "Intelligent"?

android - 无法打开 'android-release-unsigned.apk' 作为 zip 存档(zipalign 错误)

android - 循环动画集会导致 StackOverflowError

android - 使工具栏文本颜色为白色并防止重叠

android - 在现有项目React-Native中添加现有原生项目Android

android - 删除操作栏留下空白

android - 在底部导航 View 中删除操作栏