Android 徽标会在一段时间后从工具栏中消失
当我安装我的应用程序时,一切似乎都正常。但过了一会儿我回来时,我的工具栏上没有任何徽标。只有黑色的。在安卓4.4中还可以,但我的Galaxy S4升级到安卓5.0.1,我的应用程序中有这个bug。你不知道为什么吗 v21\styles.xmlAndroid 徽标会在一段时间后从工具栏中消失,android,android-actionbar,android-5.0-lollipop,toolbar,android-actionbar-compat,Android,Android Actionbar,Android 5.0 Lollipop,Toolbar,Android Actionbar Compat,当我安装我的应用程序时,一切似乎都正常。但过了一会儿我回来时,我的工具栏上没有任何徽标。只有黑色的。在安卓4.4中还可以,但我的Galaxy S4升级到安卓5.0.1,我的应用程序中有这个bug。你不知道为什么吗 v21\styles.xml <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/ColorPrimary</item>
<item name="colorPrimaryDark">@color/ColorPrimaryDark</item>
<item name="colorAccent">@color/ColorAccent</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:statusBarColor">@color/ColorPrimaryDark</item>
</style>
我找到了解决办法。黑色形状显示在操作栏中,因为“drawable”文件夹中有一个大尺寸logo.png。徽标必须采用相同尺寸的可绘制mdpi/hdpi/等(48dp/56dp高度,取决于android版本)。我不知道为什么Galaxy S4上的Android 5.0.1没有像模拟器或真正的4.4.2设备那样缩小图片的尺寸。但现在似乎还可以。尝试将setLogo()与actionbar一起使用。谢谢您的建议,但没有任何帮助。
<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="?attr/actionBarSize"
android:background="@color/ColorPrimary"
app:titleTextAppearance="@style/ToolbarTitle"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:elevation="@dimen/toolbar_elevation">
<ImageView
android:id="@+id/tool_logo"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:contentDescription="@string/img_logo"
android:src="@drawable/logo" />
</android.support.v7.widget.Toolbar>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="@color/ColorPrimary">
<ImageView
android:id="@+id/navHead"
android:layout_width="match_parent"
android:layout_height="@dimen/drawer_header_height"
android:adjustViewBounds="true"
android:src="@drawable/logo"
android:contentDescription="@string/img_logo" />
</LinearLayout>
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_list);
mDrawerList = (ListView)findViewById(R.id.navList);
final LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View drawerHeaderView = layoutInflater.inflate(R.layout.drawer_header, null);
mDrawerList.addHeaderView(drawerHeaderView);
toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);