Android将构建目标从4.1更改为3.1

Android将构建目标从4.1更改为3.1,android,Android,我试图在android studio中将我的项目构建目标从4.1更改为3.1 <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="16" /> 我知道makeCustomAnimation直到4.1才被引入…但我如何解决这个问题…我可以从4.1添加类并将其添加到3.1sdk吗???或者在ActivityOptions.makeCustomAnimation之前使用了什么方法…非常感谢您

我试图在android studio中将我的项目构建目标从4.1更改为3.1

    <uses-sdk
    android:minSdkVersion="16"
    android:targetSdkVersion="16" />
我知道makeCustomAnimation直到4.1才被引入…但我如何解决这个问题…我可以从4.1添加类并将其添加到3.1sdk吗???或者在ActivityOptions.makeCustomAnimation之前使用了什么方法…非常感谢您的帮助


感谢

正如您所发现的那样,
活动选项
直到API级别16才添加,并且在中没有提供任何等效项

因此,您有两种选择:

  • 继续针对SDK版本16,只需将
    minSdkVersion
    更改为12。然后,您可以使用if语句检查应用程序是否在运行时运行具有
    activityoptions
    类的版本。e、 g

    if (android.os.Build.VERSION.SDK_INT >= 16) {
        // Start activity with a custom animation
        Bundle bundle_animation = ActivityOptions.makeCustomAnimation(MainActivity.this, R.anim.animation, R.anim.animation2).toBundle();
        startActivity(startNewGame, bundle_animation);
    }
    else {
        // No custom animations :(
        startActivity(startNewGame);
    }
    
    请注意,可能会出现lint警告,您可以添加注释以忽略错误

  • 如果必须以SDK版本12为目标,那么您仍然可以通过使用反射在较新的设备上运行这些方法。我现在不想详细说明,因为这很复杂。。。但这仍然是一种选择


  • 希望这会有所帮助。

    使用此选项可以让新活动(DetailActivity.class)从当前活动的左侧进入

    比如:

    安装:

    Bundle bundle_animation = ActivityOptions.makeCustomAnimation(
                MainActivity.this, R.anim.animation, R.anim.animation2).toBundle();
        startActivity(startNewGame, bundle_animation);
    
    它适用于<16 API
    希望它能有所帮助:)

    嘿,非常感谢您的回复…鉴于我在android开发方面没有那么先进,我将坚持选项1:)…我试图实现您的解决方案,但我没有收到任何提示…只是“无法解析符号活动选项”您是否将AndroidManifest.xml中的android:targetSdkVersion更改为16?这将把您构建的版本改回4.1,并使
    ActivityOptions
    再次可见。我不使用Android studio,因此我不确定您是否需要执行其他操作来更改您构建的SDK版本。请您在回答中添加一些说明,好吗?
    if (android.os.Build.VERSION.SDK_INT >= 16) {
        // Start activity with a custom animation
        Bundle bundle_animation = ActivityOptions.makeCustomAnimation(MainActivity.this, R.anim.animation, R.anim.animation2).toBundle();
        startActivity(startNewGame, bundle_animation);
    }
    else {
        // No custom animations :(
        startActivity(startNewGame);
    }
    
    Intent i = new Intent(MyApplication.getContext(), DetailActivity.class);
    startActivity(i);
    getActivity().overridePendingTransition(R.anim.activtiy_pet_detail_right_slide_in, R.anim.activtiy_pet_detail_left_slide_out);
    
    Bundle bundle_animation = ActivityOptions.makeCustomAnimation(
                MainActivity.this, R.anim.animation, R.anim.animation2).toBundle();
        startActivity(startNewGame, bundle_animation);