2016-12-13 2 views
2

J'essaie de changer l'icône FloatingActionButton par défaut en icône add circle. J'ai téléchargé le icon ic_add_circle_white_18dp de material.io et l'ai ajouté au drawable directory dans le projet andorid. Cependant, lorsque je tente de l'utiliser dans mon activité, il affiche une icône noire intérieure comme dans l'imageLe bouton d'action flottant dans Android ne s'affiche pas correctement

enter image description here

Cependant, je veux l'icône FAB pour ressembler

enter image description here

icône FAB xml ressemble

<android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     app:srcCompat="@drawable/ic_add_fab" 
     app:elevation="8dp" 
     app:backgroundTint="@android:color/holo_blue_light" 
     app:rippleColor="@android:color/white"/> 

J'ai essayé de placer le app:backgroundTint val UE mais il n'a pas d'effet le style icône intérieur

Merci pour toute aide

Répondre

3

Importation Clipart correspondant à l'icône d'ajout d'actifs d'image fonctionne:

Étapes:

1. Right Click on res. 
2. Select New->Image Asset 
3. In Icon type, select Action Bar and Tab Icons 
4. Provide a name 
5. Select ClipArt in Asset type and the click on the Clip Art icon. 
6. From the content section select add button 
7. In theme set HOLO_DARK 
6. Click Next and then finish 

enter image description here

enter image description here Pour l'utiliser comme une icône, sont les suivantes dans votre XML. Notez que pour utiliser l'icône en tant que source android:src="@drawable/ic_add_fab" est utilisé

<android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@drawable/ic_add_fab" /> 
2

Essayez de télécharger et d'utiliser l'icône avec le nom « ajouter » au lieu de « ajouter cercle »

+0

Cela ne fonctionne pas non plus apparantly. –

+0

En tout cas merci, votre réponse m'a aidé à trouver la solution. Voir ma réponse pour la solution complète. Upvote pour l'aide :) –

+0

Merci :) @ShubhamKhatri –

1

Au lieu de app:srcCompat= utilisation app:src= pour les images .
Ou utilisez fab.setImageResource(R.drawable.ic_add); pour paramétrer l'image.

+0

Ne fonctionne pas non plus –

+0

Quoi qu'il en soit, merci, votre réponse m'a mis dans la bonne direction. Voir ma réponse pour la solution complète. +1 pour aider :) –

0

Vous devez définir scaleType pour qu'il soit rendu correctement:

android:scaleType="center"