更改 alpha 属性时引发错误
alpha 属性设置为视图时收到此错误
java.lang.NoSuchMethodError: android.view.View.setAlpha
我在代码中将
((View) findViewById(R.id.view)).setAlpha(100);
//with float value also doesn't works
可能是什么问题?我仅在运行时没有任何编译错误
I get this error for setting the alpha property to a view
java.lang.NoSuchMethodError: android.view.View.setAlpha
in my code
((View) findViewById(R.id.view)).setAlpha(100);
//with float value also doesn't works
What might be the problem ? I do not have any compile errors just on runtime
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如文档所述,
setAlpha
需要 API 11。您可能将 minSDK 设置为低于 11 的值,并在低于 11 的设备上安装/运行它。这意味着它没有此方法,因此 Java 无法找到它。As the documentation states,
setAlpha
requires API 11. You probably have your minSDK set to something below 11 and are installing/running this on a device which is below 11. That means it doesn't have this method, so Java can't find it.我使用代码来设置图像本身的Alpha,而不是视图。这可以从 API 级别 1 开始使用。
I used code to setAlpha of the image itself, not the view. This is available from API level 1..
您的 android:targetSdkVersion 可能高于 15,因此您可以在使用 setAlpha 时进行验证或者
Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1
的值为 15probably you have an android:targetSdkVersion higher than 15, so you can validate when use setAlpha or
the value of
Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1
is 15