2017-05-05 11 views
1

Androidで動作する画像のボタンを取得しようとしています。私は以下を試しました:Androidアイコンのmipmap値がボタンで機能しない

<Button 
     android:id="@+id/button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:icon="@mipmap/ic_launcher" /> 

ボタンはイメージなしで表示されます。

+0

? –

+0

私はちょうどテキストの代わりにイメージのボタンが欲しいです。画像はres/mipmapフォルダにあり、画像アセットをインポートした後、android studioがそれを保存します。 – user1111652

+0

アプリアイコン以外の 'mipmap'フォルダは使用しないでください。グラフィカルリソースは 'drawable'を使います。 –

答えて

1

<Button 
    android:id="@+id/button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@mipmap/ic_launcher" />` 
+0

それはやっているようです。解決策は少しハッキリですが、十分です。ありがとう! – user1111652

+0

有用であれば回答を受け入れます。 – Akshay

1

#を試してみてください。あなただけの背景ImageButtonをしたい場合は、これを試してみてください:

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@mipmap/ic_launcher"/> 

enter image description here

OR、あなたは以下のようにImageButtonを使用することができます。

<ImageButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@mipmap/ic_launcher" /> 

enter image description here

#。

<Button 
    android:id="@+id/button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="BUTTON" 
    android:background="@mipmap/ic_launcher"/> 

enter image description here

#:あなたはTextと背景ImageButtonをしたい場合は、これを試してみてください。あなたはTextButtonをしたいと描画可能Iconを残した場合は、これを試してください:あなたがイメージを置きたい

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="BUTTON" 
    android:drawableLeft="@mipmap/ic_launcher"/> 

enter image description here

関連する問題