Xamarin Android AppcombatToolbar和MobileBarcodeScanner问题

时间:2017-03-22 12:03:17

标签: xamarin xamarin.android

如果我尝试在自定义覆盖中使用AppcombatToolbar(https://developer.xamarin.com/guides/android/user_interface/toolbar/part-3-toolbar-compatibility/),则不会显示工具栏中的项目。我看到工具栏的空间但没有按钮和文字

这是我的用法:

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();

这是我的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);
        }

    }

这是我的基本布局:

<?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>

使用工具栏的页面 image

没有工作工具栏的扫描 image

0 个答案:

没有答案