[英]How do I import material design library to Android Studio?
我想將此庫導入到我在Android Studio v1.0.0 rc2 中的項目中:
https://github.com/navasmdc/MaterialDesignLibrary
但有一個問題。 當我將此庫添加為模塊時,會出現此錯誤:
錯誤:依賴項 MyApplication.libraries:MaterialDesign:項目應用程序上未指定解析為不支持作為編譯依賴項的 APK 存檔。 文件:C:\ADTBundle\StudioWorkspace\MyApplication\libraries\MaterialDesign\build\outputs\apk\MaterialDesign-release-unsigned.apk
解決此問題的分步指南是什么? 或者這個庫的 gradle 依賴項是什么?
有一個新的官方設計庫,只需將其添加到您的 build.gradle:有關詳細信息, 請訪問 android 開發者頁面
implementation 'com.android.support:design:27.0.0'
如果您使用的是 Android Studio:
您可以將項目作為模塊導入,並在導入模塊的build.gradle
文件中更改以下內容。
將應用插件: com.android.application
更改為應用插件: com.android.library
刪除applicationId
並設置minSdkVersion
以匹配您的項目 minSdkVersion。
在您的項目build.gradle
文件中compile project(':MaterialDesignLibrary')
,其中MaterialDesignLibrary
是您的庫項目的名稱,或者您可以通過 File -> Project Structure -> Select your project under Modules -> Dependencies -> 導入模塊單擊 + 添加模塊。
如果您使用的是 Android X: https ://material.io/develop/android/docs/getting-started/ 按照此處的說明進行操作
上次編輯時,最新的庫版本是
implementation 'com.google.android.material:material:1.6.0'
更新:從這里獲取最新的材料設計庫https://maven.google.com/web/index.html?q=com.google.android.material#com.google.android.material:material
對於舊版 SDK
添加與您的appcompat-v7庫相同的設計支持庫版本
您可以從 android 開發者文檔https://developer.android.com/topic/libraries/support-library/packages#design獲取最新的庫
implementation 'com.android.support:design:28.0.0'
去
如果您遷移到 AndroidX,您應該像這樣在 graddle 中添加依賴項:
com.google.android.material:material:1.0.0-rc01
API 23 的最新版本是
compile 'com.android.support:design:23.2.1'
首先,添加 Material Design 依賴項。
implementation 'com.google.android.material:material:<version>'
獲取最新的材料設計庫版本。 檢查官方網站github存儲庫。
當前版本是1.2.0 。
所以,你必須添加,
implementation 'com.google.android.material:material:1.2.0'
然后,您需要通過添加將應用程序主題更改為材料主題,
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
在你的style.xml中。 不要忘記在清單文件中的應用程序主題中設置相同的主題。
構建.gradle
implementation 'com.google.android.material:material:1.2.0-alpha02'
樣式.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
您可以像這樣將所有這些都放在app:level gradle.build中,從而為舊項目添加最新的庫支持
apply plugin: 'com.android.application'
android {
// rest code
dependencies {
implementation("com.squareup.okhttp3:okhttp:4.10.0")
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.