2016-07-14 42 views
1

它不会在应用程序中显示图标,该怎么办?Android:在应用程序中显示图标

我试图添加这种方式,但它没有奏效。

使用此方法,只更改菜单中的应用程序图标。

Image

+0

尝试与其他新图标和 –

+0

您需要使用自定义布局为你的动作条或工具栏重建项目。 – Drv

+0

http://stackoverflow.com/questions/5350624/set-icon-for-android-application/5350771#5350771 –

回答

1

一号改变杆的工具栏然后

getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
    getSupportActionBar().setDisplayShowHomeEnabled(true); 

三号 mainfest->变化图标

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
+0

这部分帮助我,现在有一个主页按钮,当我移动到另一个布局。但它仍然不显示图标。 @Cgx –

1

创建toolbar_actionbar.xml如下:

<?xml version="1.0" encoding="utf-8"?> 
<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="56dp" 
android:background="@color/colorPrimary" 
app:contentInsetEnd="0dp" 
app:contentInsetLeft="0dp" 
app:contentInsetRight="0dp" 
app:contentInsetStart="0dp"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageButton 
     android:id="@+id/imgbtn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:background="@android:color/transparent" 
     android:src="@mipmap/ic_launcher" /> 

    <TextView 
     android:id="@+id/txt_title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_marginLeft="16dp" 
     android:layout_marginStart="16dp" 
     android:layout_toEndOf="@+id/btn_back" 
     android:layout_toRightOf="@+id/btn_back" 
     android:text="Weather" 
     android:textColor="@android:color/white" 
     android:textSize="20sp" 
     android:textStyle="bold" /> 

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

在主布局文件,使用下面行添加上述布局:

<include 
     android:id="@+id/toolbar" 
     layout="@layout/toolbar_actionbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"></include> 

在你的风格,下面写在你的父主题线路:

<item name="android:windowActionBar">false</item> 
<item name="windowNoTitle">true</item> 

并添加以下行到你的活动:

Toolbar toolbar=(Toolbar)findViewById(R.id.toolbar); 
setSupportActionBar(toolbar); 

ImageButton imgbtn=(ImageButton)toolbar.findViewById(R.id.imgBtn); 
相关问题