2017-05-05 29 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

:如果你想用ButtonText左繪製Icon,試試這個? –

+0

我只想要一個圖片而不是文本的按鈕。該圖像位於res/mmapmap文件夾中,在您導入圖像資源後,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

#。如果你想與只背景Image一個Button,試試這個:

<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

#。如果你想與Text和背景Image一個Button,試試這個:

<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

#。在那裏你想要把圖像

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

enter image description here