Android-API级别21中的日期 [英] Android - Date in API Level 21

查看:61
本文介绍了Android-API级别21中的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我还是Android的新手,

Hello I'm still kinda new to Android,

目前,我对本地日期(或我尝试过的其他任何日期格式)有很大的疑问

at the moment I have a big problem with Local Date(or any other Date Format I tried)

LocalDate currentDate = LocalDate().now();

此行产生以下错误:

Call requires API Level 26 (current min is 21)

我完全理解这是什么意思,但是我无法更改项目的API级别(由于我与老师签订了一项合同,我和合作伙伴将以这样的方式使我们的学校项目在实践中成为现实,计划了.)

I perfectly understands what this means, but I can't change the API Level of the project (due to the fact that I singed a contract with my teacher that me and a partner will make our school project in excact that way we planned it.)

如何在API级别21中使用任何类型的日期?

How can I use any kind of Date with API Level 21?

等级:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.fragment"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "0.5"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

        }
    }
    android {
        compileOptions {
            coreLibraryDesugaringEnabled true
        }
    }
}


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.firebase:firebase-database:19.2.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'com.firebase:firebase-client-android:2.5.2'
    implementation 'com.google.android.gms:play-services-auth:17.0.0'
    implementation 'me.dm7.barcodescanner:zxing:1.9'
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:22.0.0'
    implementation 'com.google.code.gson:gson:2.8.6'

}

推荐答案

将此添加到您的build.gradle文件中:

Add this to your build.gradle file:

android {
  compileOptions {
    coreLibraryDesugaringEnabled true
  }
}

较新版本的Android Gradle插件(从4.0开始)可以使用desugaring将新的API反向移植到较旧的Android版本.您可以在此处了解更多信息: https://jakewharton.com/d8-library-desugaring/

Newer versions of the Android Gradle plugin (starting with 4.0) are able to use desugaring to backport new APIs to older versions of Android. You can read more about it here: https://jakewharton.com/d8-library-desugaring/

请注意,您必须使用Android Studio的Beta版本才能访问以下功能: https://developer.android.com/studio/preview

Note that you'll have to use the Beta release of Android Studio to access these features: https://developer.android.com/studio/preview

这篇关于Android-API级别21中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆