我在Andrdoid Xamarin中实现了Resources.GetDrawable。该程序可以运行,但是如果我单击实现Resources.GetDrawable的按钮,则该程序将强制关闭。这是我的代码:

SetContentView(Resource.Layout.Main);
drawView = FindViewById<DrawingView>(Resource.Id.drawing);
LinearLayout paintLayout = FindViewById<LinearLayout>(Resource.Id.paint_colors);
currPaint = (ImageButton)paintLayout.GetChildAt(0);
currPaint.SetImageDrawable(Resources.GetDrawable(Resource.Drawable.paint_pressed));
Resources.GetDrawable(Resource.Drawable.paint_pressed带有绿色下划线(在Visual Studio 2015中为Xamarin)。日志消息返回异常:



对于Java版本,解决方案是使用以下3种之一:
ResourcesCompat.getDrawable(getResources(), R.drawable.name, null);
//or
ContextCompat.getDrawable(getActivity(), R.drawable.name);
//or
ResourcesCompat.getDrawable(getResources(), R.drawable.name, anotherTheme);

C#Android Xamarin的版本是什么?,谢谢。

最佳答案

像这样更改为SetImageResource

currPaint.SetImageResource(Resource.Drawable.paint_pressed);

关于C#-Resources.GetDrawable在Android Xamarin中已过时,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39546964/

10-09 04:36