我嘗試在Pre-Lollipop設備上運行我的應用程序。但是,這段代碼給我展示了Pre-Lolliop和棒棒糖設備的相同錯誤。
如果我將「android:」添加到樣式21中的樣式中,棒棒糖設備可以正常工作,但會顯示一些像android:color要求Android lvl 21(當前Api lvl爲17)的錯誤。用於前棒棒糖和棒棒糖設備的材料設計顏色不起作用
風格
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme.Base" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="textColor">@color/primary_dark</item>
<item name="editTextColor">@color/primary_dark</item>
<item name="textColorPrimary">@color/icons</item>
<item name="imageButtonStyle">@color/icons</item>
</style>
<style name="MyCustomToolbarTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="textColorPrimary">@color/icons</item>
<item name="textColorSecondary">@color/primary_light</item>
<item name="colorControlHighlight">@color/icons</item>
</style>
</resources>
styles21
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:colorPrimary">@color/primary</item>
<item name="android:colorPrimaryDark">@color/primary_dark</item>
<item name="android:colorAccent">@color/accent</item>
<item name="android:textColor">@color/primary_dark</item>
<item name="android:editTextColor">@color/primary_dark</item>
<item name="android:textColorPrimary">@color/icons</item>
<item name="android:imageButtonStyle">@color/icons</item>
</style>
<style name="MyCustomToolbarTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:textColorPrimary">@color/icons</item>
<item name="android:textColorSecondary">@color/primary_light</item>
<item name="android:colorControlHighlight">@color/icons</item>
</style>
</resources>
顏色
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary">#4CAF50</color>
<color name="primary_dark">#388E3C</color>
<color name="primary_light">#C8E6C9</color>
<color name="accent">#8BC34A</color>
<color name="primary_text">#212121</color>
<color name="secondary_text">#727272</color>
<color name="icons">#FFFFFF</color>
<color name="divider">#B6B6B6</color>
</resources>
搖籃
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.hansbaum.calculator"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:appcompat-v7:23.+"
}
清單
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.hansbaum.calculator">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
錯誤
謝謝,但不工作。 –
在build.gradle文件 –
中更新buildToolsVersion '23 .0.2'不起作用。始終是相同的錯誤信息 –