我尝试使用xamarin component在我的应用程序中集成FloatingActionButton。在布局膨胀时,它会引发异常"无法激活Java类型的JNI句柄0xffb8b288(key_handle 0x3ee746ea)' com / refractored / fab / FloatingActionButton'作为托管类型' com.refractored.fab.FloatingActionButton'。"
布局文件
<?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>
活动代码:
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)
{
}
}
}
目标sdk版本为23,最小版本为16
Upadted android支持V4,V7 AppCompat(23.1.1.0)和refractored.fab(1.4.0)包。
来自xamarin组件的示例代码工作正常,没有任何问题
这个例外可能是什么原因?任何建议/提示表示赞赏
谢谢
答案 0 :(得分:2)
该组件已被弃用,支持使用FloatingActionButton
的支持库版本。您可以删除该组件,并确保包含Nuget(23.1.1.0)中的最新设计库包Nuget Link。然后你应该能够做到以下几点。
<android.support.design.widget.FloatingActionButton
...
android:id="@+id/fab" />
在你的代码中使用它
using Android.Support.Design.Widget;