假设我开发了一个 android 库 XYZ,它有方法
animateWithTransition() 包含与 Transition api 相关的代码(即 minsdk=21)
animateSimply() 具有简单的动画效果。
当客户使用 XYZ 库时,如果他的 minsdk < 21,他应该能够看到 animateWithTransition() 作为建议(ctrl+space)。强> 并且应该只能看到 animateSimply() : |
如何解决这个问题?
最佳答案
您应该尝试以下列方式构建您的代码 -
public void performAnimation() {
if(Build.VERSION.SDK_INT < 21 )
{
// write code for animateSimply function here
}
else
{
// write code for animateWithTransition function here
}
}
那样的话,您将拥有单一功能(这意味着更少的代码、干净的代码)和更容易的测试。此外,您的客户只需调用 1 个函数,这使他/她更容易使用您的库。
关于java - 基于sdk android更改方法的可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44581740/