2017-04-03 67 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