2017-06-20 1 views
0

Ich habe ein actionLayout, das auf meiner Symbolleiste als Benachrichtigungssymbol fungiert. Wenn ich mein Telefon in ltr habe, funktioniert alles gut. Wenn ich mein Telefon zu rtl locale umgebe, verschwinden das Abzeichen und das Menüsymbol, obwohl sie Platz auf der Symbolleiste nehmen und auf sie klicken, funktioniert. Kann mir jemand sagen, was ich falsch mache?ActionLayout wird nicht angezeigt, wenn LayoutDirection auf rtl eingestellt ist

Code

public override void OnCreateOptionsMenu(IMenu menu, MenuInflater inflater) 
     { 
      inflater.Inflate(Resource.Menu.welcome_menu, menu); 

      using (var icon = menu.FindItem(Resource.Id.action_notification)) 
      { 
       icon.Icon.ApplyDrawableTint(MobileSettingsManager.Instance.MobileSettings.Theme.NavigationBar.Icon); 
       if ((Activity as BaseActivity).IsRtl() && Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat) 
       { 
        icon.Icon.AutoMirrored = true; 
        var notification = menu.FindItem(Resource.Id.action_notification).ActionView; 
        notification.Click += async delegate 
        { 
         if (Utils.IsOnline(Context)) 
          await MoveToNotifications(); 
        }; 
        _badge = notification.FindViewById<TextView>(Resource.Id.tv_notif_count); 
        _badge.ApplyFont(); 
        _badge.Visibility = ViewStates.Gone; 
       } 
      } 
      using (var icon = menu.FindItem(Resource.Id.action_filter)) 
       icon.Icon.ApplyDrawableTint(MobileSettingsManager.Instance.MobileSettings.Theme.NavigationBar.Icon); 
     } 

welcome_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_filter" 
    android:icon="@drawable/ic_filter" 
    app:showAsAction="always"/> 

    <item 
    android:id="@+id/action_notification" 
    app:actionLayout="@layout/action_notification_badge" 
    android:icon="@drawable/notification_bell" 
    app:showAsAction="always"/> 
</menu> 

action_notification_badge.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:clickable="true" 
       android:background="@android:color/transparent" 
    style="@android:style/Widget.ActionButton"> 
    <ImageView 
     android:id="@+id/hotlist_bell" 
     android:src="@drawable/notification_bell" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:layout_marginEnd="8dp" 
     android:layout_marginTop="8dp" 
     android:contentDescription="bell" /> 
    <TextView 
     android:id="@+id/tv_notif_count" 
     android:layout_width="wrap_content" 
     android:minWidth="17sp" 
     android:textSize="10sp" 
     android:textColor="#ffffff" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:text="@null" 
     android:backgroundTint="#ff0000" 
     android:layout_alignTop="@id/hotlist_bell" 
     android:layout_alignEnd="@id/hotlist_bell" 
     android:layout_marginBottom="4dp" 
     android:layout_marginStart="4dp" 
     android:background="@drawable/rounded_square" /> 
</RelativeLayout> 

rounded_square.xml

<?xml version="1.0" encoding="utf-8" ?> 
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="oval"> 
    <solid 
     android:color="#a3a3a3"/> 
</shape> 

Antwort

0

Gut, nachdem ich einen Tag mit diesem Bug verschwendet habe, weil ich einen LinearLayout anstelle von RelativeLayout als Root für meine action_notification_badge.xml verwenden musste. Im Allgemeinen, mit RelativeLayout Dinge werden durcheinander gebracht (z. B. können Sie nicht benutzerdefinierte Marker Info-Fenster in googlemaps mit als Root-Element) so immer lieber LinearLayout. Mein endgültiger Code für action_notification_badge.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:clickable="true" 
       android:orientation="horizontal" 
    style="@android:style/Widget.ActionButton" > 
    <RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <ImageView 
     android:id="@+id/hotlist_bell" 
     android:src="@drawable/ic_notification" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:layout_marginEnd="8dp" 
     android:contentDescription="bell" /> 
    <TextView 
     android:id="@+id/tv_notif_count" 
     android:layout_width="wrap_content" 
     android:minWidth="17sp" 
     android:textSize="10sp" 
     android:textColor="#ffffff" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@id/hotlist_bell" 
     android:layout_alignEnd="@id/hotlist_bell" 
     android:textDirection="locale" 
     android:textAlignment="gravity" 
     android:gravity="center" 
     android:background="@drawable/rounded_square" 
     android:layout_marginBottom="8dp" 
     android:layout_marginStart="8dp" 
     android:text="@null" /> 
    </RelativeLayout> 
</LinearLayout> 
Verwandte Themen