Android Appcompat工具栏标题未正确显示
我正在使用版本支持库中的支持工具栏Android Appcompat工具栏标题未正确显示,android,android-toolbar,android-design-library,Android,Android Toolbar,Android Design Library,我正在使用版本支持库中的支持工具栏25.0.1,它随机显示如下: 现在这是随机的,我不知道如何重现。有时显示正常,有时显示不正确 以下是我在片段中使用工具栏的方式: <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" xmlns:android="http://schemas.android.com/apk/res
25.0.1
,它随机显示如下:
现在这是随机的,我不知道如何重现。有时显示正常,有时显示不正确
以下是我在片段中使用工具栏的方式:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
android:id="@+id/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="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/Theme.App.Toolbar"
android:elevation="@dimen/toolbar_elevation"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/Theme.App.Toolbar.Popup"/>
<style name="Theme.App.Toolbar">
<item name="android:textColorPrimary">@color/white</item>
<item name="actionMenuTextColor">@color/white</item>
<item name="android:textColorSecondary">@color/white</item>
<item name="android:textColorHint">@color/white</item>
</style>
从尖叫声中可以看出,工具栏试图放置字幕,但我没有
这是否发生在其他人身上,这是否是此问题的已知错误,是否有任何解决方案。到目前为止,我唯一的解决方案是使用支持库版本
25.0.0
欢迎使用其他解决方案或更新尝试如下使用:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/tb_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:theme="@style/Theme.MyTheme"
tools:ignore="NewApi">
<TextView
android:id="@+id/tv_title_toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="@android:color/white"
android:textSize="18sp"
/>
</android.support.v7.widget.Toolbar>
我不想自定义它,想象一下,对于一个现有的项目,你将不得不到处设置文本标题而不是toolbar.setTitle。我相信在将来,这一问题会得到解决。是的,与此同时,您必须坚持使用较旧版本的support library 25.0.0,或者您可以使用上述解决方案自定义工具栏
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/tb_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:theme="@style/Theme.MyTheme"
tools:ignore="NewApi">
<TextView
android:id="@+id/tv_title_toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="@android:color/white"
android:textSize="18sp"
/>
</android.support.v7.widget.Toolbar>
toolbar = (Toolbar) findViewById(R.id.tb_toolbar);
tvToolbarTitle = (TextView) toolbar.findViewById(R.id.tv_title_toolbar);
tvToolbarTitle.setText(title);