Issue with Xamarin Android AppcombatToolbar and ZXING MobileBarcodeScanner

If I try to use the AppcombatToolbar (https://developer.xamarin.com/guides/android/user_interface/toolbar/part-3-toolbar-compatibility/) in a customoverlay the items in my toolbar are not displayed. I see the space of the toolbar but without buttons and text

This is my zxing usage:

var scanner = new ZXing.Mobile.MobileBarcodeScanner();

                //Tell our scanner we want to use a custom overlay instead of the default
                scanner.UseCustomOverlay = true;

                //Inflate our custom overlay from a resource layout
                View zxingOverlay = LayoutInflater.FromContext(this).Inflate(Resource.Layout.Master, null);

                //Set our custom overlay
                scanner.CustomOverlay = zxingOverlay;

                //Start scanning!
                var result = await scanner.Scan();

This my BaseActivity

[Activity(Label = "@string/app_name", MainLauncher = false, Icon = "@drawable/icon")]
    public class MasterActivity : AppCompatActivity
    {
        LinearLayout content;
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            base.SetContentView(Resource.Layout.Master);

            // Create your application here
            var toolbar = FindViewById<Toolbar>(Resource.Id.maintoolbar);
            SetSupportActionBar(toolbar);
            SupportActionBar.Title = GetString(Resource.String.app_name);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetHomeButtonEnabled(true);

            content = (LinearLayout)FindViewById(Resource.Id.content);
        }

        public override void SetContentView(int id)
        {
            LayoutInflater inflater = (LayoutInflater)BaseContext.GetSystemService(Context.LayoutInflaterService);
            if (content != null)
            {
                inflater.Inflate(id, content);
            }
        }

        public override bool OnCreateOptionsMenu(IMenu menu)
        {
            MenuInflater.Inflate(Resource.Menu.topmenus, menu);
            return base.OnCreateOptionsMenu(menu);
        }

        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            if(item.ItemId == Resource.Id.menu_logout)
            {
                Settings.UserName = null;
                Settings.Password = null;
                StartActivity(typeof(LoginActivity));
            }
            Toast.MakeText(this, "Action selected: " + item.TitleFormatted,
                ToastLength.Short).Show();
            return base.OnOptionsItemSelected(item);
        }

    }

And this my Base Layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:minWidth="25px"
    android:minHeight="25px"
    android:weightSum="1">
  <include
    android:id="@+id/maintoolbar"
        layout="@layout/toolbar" />
    <LinearLayout
        android:id="@+id/content"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" 
        android:background="@android:color/transparent"/>
</LinearLayout>

Page with working Toolbar
image

Scanpage with no working toolbar
image

Sign In or Register to comment.