2016-07-14 10 views
1

アイコンはアプリケーションに表示されません。どうしたらいいですか?Android:アプリケーションのアイコンを表示

この方法で追加しようとしましたが、機能しませんでした。

この方法では、メニューのアプリケーションアイコンのみを変更しました。

Image

+0

他の新しいアイコンを試して、プロジェクトを再構築してください。 –

+0

アクションバーまたはツールバーのカスタムレイアウトを使用する必要があります。 – Drv

+0

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

答えて

1

No.1の変更バーツールバーに続い

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

3番 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); 
関連する問題