【发布时间】:2016-02-12 12:58:08
【问题描述】:
当我尝试以编程方式更改 ToolBar 时遇到了一些麻烦。
当我从代码中更改 ToolBar 标题,当我在真实设备上运行程序时,我的工具栏标题是“MyAppName @2131558664”,但我只设置了“MyAppName”
我也有带有片段的 ViewPager,在其中一个片段中我得到工具栏并更改工具栏菜单(添加 SearchView ),当我也启动程序并打开 SearchView 我的查询也包含这个“@2131558664”。为什么会发生?我该如何解决? 感谢回复
工具栏.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?android:actionBarSize"
app:theme="@style/MyToolBar"
android:layout_centerHorizontal="true"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark">
</android.support.v7.widget.Toolbar>
MyToolBar 主题:
<style name="MyToolBar" parent="Theme.AppCompat.Light">
<item name="android:text">@style/TextAppearance.Widget.Event.Toolbar.Title</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
<item name="android:textColorPrimary">@color/colorAccent</item>
<item name="android:textColorSecondary">@color/colorAccent</item>
</style>
我更改的片段 ToolBar:
Toolbar toolbar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setTitle("MyAppName");
【问题讨论】:
标签: android android-fragments android-actionbar android-toolbar