簡體   English   中英

如何將材料設計庫導入 Android Studio?

[英]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'

  1. 文件(左上角)
  2. 項目結構
  3. 在模塊下。 找到依賴選項卡
  4. 按右上角的加號按鈕 (+)。
  5. 你會發現所有的依賴

如果您遷移到 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM