我在 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)。日志消息返回异常:
Android.Content.Res.Resources+NotFoundException
'Resources.GetDrawable(int)' is obsolete: 'deprecated'
对于 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 的版本是多少?谢谢。
最佳答案
var currPaint= ContextCompat.GetDrawable(this,Resource.Drawable.paint_pressed);
currPaint.SetBounds(0, 0, 60, 60);
This is what i have implimented in my project even i had same problem.Hope this helps! @Jake
关于C# - Resources.GetDrawable 在 Android Xamarin 中已过时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39546964/