简体   繁体   English

无法使用Xamarin.Android中的浮动操作按钮激活JNI句柄异常

[英]Could not activate JNI Handle exception with Floating action button in Xamarin.Android

I'm trying to integrate FloatingActionButton in my application using the xamarin component . 我正在尝试使用xamarin组件在我的应用程序中集成FloatingActionButton。 On layout inflation it throws the exception "Could not activate JNI Handle 0xffb8b288 (key_handle 0x3ee746ea) of Java type 'com/refractored/fab/FloatingActionButton' as managed type 'com.refractored.fab.FloatingActionButton'." 在布局膨胀时,它抛出异常“无法激活Java类型'com / refractored / fab / FloatingActionButton'的JNI句柄0xffb8b288(key_handle 0x3ee746ea)作为托管类型'com.refractored.fab.FloatingActionButton'。”

在此输入图像描述

layout file 布局文件

    <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:fab="http://schemas.android.com/apk/res-auto"
             android:layout_width="match_parent"
             android:layout_height="match_parent"> 
    <ListView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent" /> 
    <com.refractored.fab.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            android:layout_margin="16dp"
            android:src="@drawable/ic_edit"
            fab:fab_colorNormal="@color/primary"
            fab:fab_colorPressed="@color/primary_pressed"
            fab:fab_colorRipple="@color/ripple" />
</FrameLayout>

Activity code : 活动代码:

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS; 
using Android.Support.V4.App; 
using ActionBar =  Android.Support.V7.App.ActionBar;
using Android.Text;
using com.refractored.fab;  
using Android.Support.V7.App; 

namespace SampleActionBar
{
    [Activity (Label = "SampleActionBar", MainLauncher = true, Icon = "@mipmap/icon")]
    public class MainActivity : ActionBarActivity, ActionBar.ITabListener
    { 
        protected override void OnCreate (Bundle savedInstanceState)
        {
            base.OnCreate (savedInstanceState);
            InitActionBar (); 
        } 
        private void InitActionBar()
        {
            if (SupportActionBar == null)
                return;

            var actionBar = SupportActionBar;
            actionBar.NavigationMode = (int)ActionBarNavigationMode.Tabs;

            var tab1 = actionBar.NewTab();
            tab1.SetTabListener(this);
            tab1.SetText("ListView");
            actionBar.AddTab(tab1); 
        }
        public void OnTabReselected(ActionBar.Tab tab, Android.Support.V4.App.FragmentTransaction ft)
        {
        } 
        public void OnTabSelected(ActionBar.Tab tab, Android.Support.V4.App.FragmentTransaction ft)
        {
            switch (tab.Text)
            {
            case "ListView":
                ft.Replace(Android.Resource.Id.Content, new ListViewFragment());
                break; 
            }
        } 
        public void OnTabUnselected(ActionBar.Tab tab, Android.Support.V4.App.FragmentTransaction ft)
        { 
        } 
    } 
    public class ListViewFragment:Android.Support.V4.App.Fragment, IScrollDirectorListener, AbsListView.IOnScrollListener
    {
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var root = inflater.Inflate(Resource.Layout.Main, container, false);

            var list = root.FindViewById<ListView>(Android.Resource.Id.List);
            var adapter = new ListViewAdapter(Activity, Resources.GetStringArray(Resource.Array.countries));
            list.Adapter = adapter;

            var fab = root.FindViewById<FloatingActionButton>(Resource.Id.fab);
            //fab.AttachToListView(list, this, this);
            fab.Click += (sender, args) =>
            {
                Toast.MakeText(Activity, "FAB Clicked!", ToastLength.Short).Show();
            };
            return root;
        }
        public void OnScrollDown()
        { 
        }

        public void OnScrollUp()
        { 
        }

        public void OnScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
        { 
        }

        public void OnScrollStateChanged(AbsListView view, ScrollState scrollState)
        { 
        }
    }
}

Target sdk version is 23 and min version is 16. 目标sdk版本为23,最小版本为16。
Upadted android support V4,V7 AppCompat(23.1.1.0) and refractored.fab(1.4.0) package. Upadted android支持V4,V7 AppCompat(23.1.1.0)和refractored.fab(1.4.0)包。
Sample code from xamarin component works fine without any issues 来自xamarin组件的示例代码工作正常,没有任何问题
What might be the cause for this exception? 这个例外可能是什么原因? any suggestion/hints are appreciated. 任何建议/提示表示赞赏。
Thank you 谢谢

That component has been deprecated in favor of using the Support Library version of the FloatingActionButton . 该组件已被弃用,支持使用FloatingActionButton的支持库版本。 You can remove that component and make sure to include the latest design library package Nuget Link from Nuget (23.1.1.0). 您可以删除该组件,并确保包含Nuget(23.1.1.0)中的最新设计库包Nuget Link Then you should be able to do the following. 然后你应该能够做到以下几点。

<android.support.design.widget.FloatingActionButton
  ...
  android:id="@+id/fab" />

With this in your code using Android.Support.Design.Widget; 在你的代码中using Android.Support.Design.Widget;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM