-1

当我安装我的应用程序时,一切似乎都没问题。但是当我稍后回来时,我的工具栏中没有徽标。只有黑色。在Android 4.4中是可以的,但我的Galaxy S4已升级到Android 5.0.1,并且在我的应用程序中有这个错误。你不知道为什么要吗?徽标从工具栏中消失后

V21 \ styles.xml

<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> 

toolbar.xml

<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> 

和相同的是在抽屉报头(工具栏或抽屉头有时黑色...不是两者)

drawer_header.xml

<?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> 

没有什么特别的,我MainOverview.java

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); 
+0

尝试使用setLogo()和操作栏。 – Harry

+0

谢谢你的建议,但它没有帮助。 –

回答

0

我找到了解决方案。黑色形状显示在操作栏中,因为一个big-size logo.png位于“drawable”文件夹中。标志必须在drawable-mdpi/hdpi/etc中。大小相同(48dp/56dp高度,取决于android版本)。我不知道为什么在Galaxy S4上的Android 5.0.1不会缩小像仿真器或真正的4.4.2设备那样的图像。但现在看起来没问题。