2017-04-03 28 views
0

我使用的代码在Java中这些行:添加图标(标识) - 空活动

getSupportActionBar().setDisplayUseLogoEnabled(true); 
getSupportActionBar().setDisplayShowHomeEnabled(true); 
getSupportActionBar().setIcon(R.drawable.logo); 

可是我的标志是这样的:

LOGO:

enter image description here

如何设置此徽标的宽度,或者它实际上看起来像徽标? :)

+0

什么是您的标志图像的大小? –

+0

300x300像素。 – Tocal

+0

减小尺寸并检查它 –

回答

0

您可以在工具栏中添加图像并相应地排列在中心。

<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="?attr/colorPrimary"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:src="@drawable/logo"/> 

</android.support.v7.widget.Toolbar> 
+0

我在哪里可以添加此代码实际上? – Tocal

+0

转到布局XML文件的活动或片段,将其添加到顶部。查看此链接了解关于工具栏及其用法的更多信息[Toolbar usage](http://guides.codepath.com/android/handling-scrolls-with-coordinatorlayout) – mpals

+0

噢,好吧。我现在知道了。谢谢! :) – Tocal