2016-12-30 2 views
3

überlappt ich ein Wagen Menüsymbol mit Abzeichen und layler-Liste erstellen, aber ich fand, dass auf API 23 das Menü-Symbol unerwünschten Hintergrund erhält.Menüpunkt Symbol immer in API 23

enter image description here

activity_menu.xml

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 


    <item 
     android:id="@+id/action_cart1" 
     android:icon="@drawable/ic_menu_cart" 
     android:title="Cart" 
     app:showAsAction="always" /> 
</menu> 

ic_menu_cart.xml

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item 
     android:drawable="@drawable/cart" 
     android:gravity="center" /> 

    <!-- set a place holder Drawable so android:drawable isn't null --> 
    <item 
     android:id="@+id/ic_badge" 
     android:drawable="@drawable/cart" /> 
</layer-list> 

unten ist der Code den Warenkorb Anzahl zu aktualisieren.

public static void setBadgeCount(Context context, LayerDrawable icon, String count) { 

     BadgeDrawable badge; 

     // Reuse drawable if possible 
     Drawable reuse = icon.findDrawableByLayerId(R.id.ic_badge); 
     if (reuse != null && reuse instanceof BadgeDrawable) { 
      badge = (BadgeDrawable) reuse; 
     } else { 
      badge = new BadgeDrawable(context); 
     } 

     badge.setCount(count); 
     icon.mutate(); 
     icon.setDrawableByLayerId(R.id.ic_badge, badge); 
    } 

Ich habe die XML für verschiedene APIs erstellt, aber nicht funktioniert. Ich möchte den Hintergrund entfernen. Bitte helfen !!

Antwort

1

Da ich verstehe Sie Abzeichen Zahl und Symbol hinzuzufügen haben. Also fügen Sie unten hinzu, es funktioniert.

app:actionLayout="@layout/notification_layout" 

im <item> und erstellen notification_layout.xml Layout und setzen Sie, was Sie wollen.

so Ihre activity_main.xml sieht wie folgt aus.

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 


    <item 
     android:id="@+id/action_cart1" 
     android:orderInCategory="100" 
     android:icon="@drawable/ic_menu_cart" 
     android:title="Cart" 
     app:showAsAction="always" 
     android:title="ABD" 
     app:actionLayout="@layout/notification_layout" /> 
</menu> 

notification_layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="40.0dip" 
    android:layout_height="wrap_content" 
    android:layout_gravity="right" 
    android:clickable="false" 
    android:focusable="false" 
    android:focusableInTouchMode="false"> 
<!-- Menu Item Image --> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:clickable="false" 
     android:focusable="false" 
     android:focusableInTouchMode="false" 
     android:scaleType="center" 
     android:src="@drawable/ic_navigation_cart_white" /> 
<!-- Badge Count --> 
    <TextView 
     android:id="@+id/actionbar_notifcation_textview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_marginTop="12.0dip" 
     android:layout_marginRight="5.0dip" 
     android:gravity="center" 
     android:minHeight="15.0dip" 
     android:minWidth="15.0dip" 
     android:paddingLeft="3.0dip" 
     android:paddingRight="3.0dip" 
     android:textSize="10.0sp" 
     android:background="@drawable/TextView_design" 
     android:textColor="@android:color/white" /> 
</RelativeLayout> 

Ausgabe wie folgt aus:

enter image description here

+0

Könnten Sie mir mit notification_layout.xml Code helfen. –

+0

Ich brauche genau das, was Sie auf dem Bild gezeigt –

+0

@KuldeepDubey sehe ich meine 'notificaton.layout.xml' Datei hinzufügen, jetzt das Bild ändern und das Ergebnis zu sehen. – Ironman

Verwandte Themen