2016-11-07 55 views
0

如何将ActionBar的标志图标设置为自定义图像?类似于它如何在WhatsApp上工作?我试图实现,但它看起来像这样.. enter image description here在ActionBar中自定义图像而不是徽标

如何删除空间?

我用这样的

getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
getSupportActionBar().setDisplayUseLogoEnabled(true); 
getSupportActionBar().setIcon(R.drawable.dummy_user_profile_pic); 

和清单

<application 
     android:logo="@drawable/dummy_user_profile_pic" 

什么即时做错了什么?请指导我。非常感谢

+0

你能分享'dummy_user_profile_pic'内容的工具栏里面的文字没有使用getSupportactionbar.setTitle()方法? – SlashG

+0

这是PNG图像 –

+0

我认为问题是与该图像...我已经改变了正确的空间去..但箭头和图像之间,空间显示.. –

回答

0

我提到这link,我能够实现它。但是主页和图片之间的空间是默认空间来自App-compat支持库工具栏 Where在Whatsapp没有空间。我认为他们没有使用支持库工具栏。将标题提供给操作栏时,您可以看到默认空间。

0

使用

setLogo(R.drawable.dummy_user_profile_pic);

在你的代码,而不是

的setIcon(R.drawable.dummy_user_profile_pic)

;

它应该工作得很好。

+0

雅第一我试着用SetLogo只有它不工作..然后我更改为SetIcon,这也不工作.. –

+0

尝试使用: 'getActionBar.setIcon(R.drawable.dummy_user_profile_pic);'在你的代码中。 – hittsss

+0

还可以改变你的Android清单XML文件: – hittsss

0
With toolbar you can easily customize actionbar as shown below 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="@color/black" 
     app:popupTheme="@style/AppTheme.PopupOverlay"> 

     <ImageView 
      android:layout_width="40dip" 
      android:layout_height="40dip" 
      android:layout_gravity="center_vertical" 
      android:layout_marginRight="10dip" 
      android:src="@drawable/logo" /> 

     <TextView android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:text="Sample" 
      android:layout_weight="1" 
      android:id="@+id/title_textview" 
      android:textColor="@android:color/white" 
      android:gravity="center"/> 

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

注意:在使用本 只需设置的TextView的

+0

像这样的相同用于我提到的那个链接...检查包括布局在工具栏小部件... –

相关问题