android 中缺少样式
Missing styles in android
我正在使用 android studio 2.2.3。我所有的布局 xml 都在抱怨 "Missing styles"。以下是我在打开设计视图时遇到的错误。
呈现问题缺少样式。是否为此布局选择了正确的主题?使用布局上方的主题组合框选择不同的布局,或修复主题样式引用。 Failed to find style 'progressBarStyle' in current theme (1568 similar errors not shown) Failed to find '?attr/textAppearanceSmall' in current theme. (未显示 65 个类似错误)
我也注意到 styles.xml 找不到 "Theme.AppCompat.Light.NoActionBar"。我已经检查了项目结构,并且能够在依赖项列表中看到 com.android.support.appcompat-v7:25.2.0。我执行了无效缓存并重新启动,clean/build。但我无法摆脱缺少样式的问题。我还尝试将我的 "AppTheme" 重命名为 "AppBaseTheme" 并在我的 android 清单文件中引用它。即使那样也无济于事。我已经尝试在设计视图中进行刷新,但仍然无法摆脱缺少样式的错误。
对于另一个 xml 布局,我收到以下错误
Rendering Problems Missing styles. Is the correct theme chosen for this layout? >Use the Theme combo box above the layout to choose a different layout, or fix the theme style references. The following classes could not be instantiated:
- android.support.design.widget.TabLayout (Open Class, Show Exception, Clear Cache)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE. If this is an unexpected error you can also try to build the project, then manually refresh the layout. Exception Details java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library. at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:36) at android.support.design.widget.TabLayout.(TabLayout.java:297) at android.support.design.widget.TabLayout.(TabLayout.java:291) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) at android.view.LayoutInflater.rInflate(LayoutInflater.java:834) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) at android.view.LayoutInflater.inflate(LayoutInflater.java:518) at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
有人能给我指出正确的方向吗?谢谢。
以下是我的清单。
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:name=".ExampleApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".activity.SplashActivity"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".activity.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize"/>
</application>
以下是我的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "com.example.package"
minSdkVersion 18
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
jackOptions {
enabled true
}
dexOptions {
preDexLibraries true
javaMaxHeapSize "4g"
}
lintOptions {
abortOnError false
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
testOptions {
unitTests.returnDefaultValues = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
compile 'com.android.support:recyclerview-v7:25.2.0'
compile 'com.android.support:cardview-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.android.support:appcompat-v7:25.2.0'
compile group: 'joda-time', name: 'joda-time', version: '2.9.6'
compile group: 'com.google.guava', name: 'guava', version: '20.0'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'com.github.zagum:Android-SwitchIcon:1.3.2'
compile 'com.futuremind.recyclerfastscroll:fastscroll:0.2.5'
compile 'com.prolificinteractive:material-calendarview:1.4.2'
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
compile 'com.google.dagger:dagger:2.7'
annotationProcessor 'com.google.dagger:dagger-compiler:2.7'
testCompile 'junit:junit:4.12'
testCompile "org.robolectric:robolectric:3.0"
testCompile "org.robolectric:shadows-support-v4:3.0"
testCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
compile 'com.android.support.constraint:constraint-layout:1.0.0'
}
以下是我的styles.xml.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="android:textViewStyle">@style/RobotoTextViewStyle</item>
<item name="android:editTextStyle">@style/RobotoEditTextStyle</item>
</style>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/splash</item>
</style>
<style name="RobotoTextViewStyle" parent="android:Widget.TextView">
<item name="android:fontFamily">sans-serif</item>
<item name="android:textSize">@dimen/body</item>
<item name="android:textColor">@color/colorBlack</item>
</style>
<style name="RobotoEditTextStyle" parent="android:Widget.EditText">
<item name="android:fontFamily">sans-serif</item>
<item name="android:textSize">@dimen/body</item>
<item name="android:padding">@dimen/edittext_padding</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@android:color/white</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
<style name="TextInputLayoutStyle" parent="TextAppearance.AppCompat.Small">
<item name="android:textColor">@color/color_android_green</item>
<item name="android:textStyle">bold|italic</item>
</style>
<style name="TextInputLayoutStyleError" parent="TextAppearance.AppCompat.Small">
<item name="android:textColor">@color/colorRed</item>
<item name="android:textStyle">bold|italic</item>
</style>
<style name="CustomTextStyle" parent="@android:style/TextAppearance.Widget.TabWidget">
<item name="android:textSize">20sp</item>
</style>
<style name="CustomSwitch" parent="Theme.AppCompat.Light">
<!-- active thumb & track color (30% transparency) -->
<item name="colorControlActivated">@color/colorAccent</item>
<!-- inactive thumb color -->
<item name="colorSwitchThumbNormal">@color/colorGrayDarker</item>
<!-- inactive track color (30% transparency) -->
<item name="android:colorForeground">@color/colorGray</item>
</style>
<style name="CustomTabLayout" parent="Base.Widget.Design.TabLayout">
<item name="tabIndicatorColor">@color/colorGold</item>
<item name="tabSelectedTextColor">@color/colorGold</item>
</style>
<style name="StyledScrollerTextAppearance">
<item name="android:textColor">@color/colorWhite</item>
</style>
Tablayout xml 片段
<android.support.design.widget.TabLayout
android:id="@+id/callScheduleType"
style="@style/CustomTabLayout"
android:layout_width="0dp"
android:layout_height="40dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/guidelineNavHeight">
<android.support.design.widget.TabItem
android:id="@+id/personal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="personal"/>
<android.support.design.widget.TabItem
android:id="@+id/community"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="community"/>
</android.support.design.widget.TabLayout>
我能够通过将项目顶级构建文件中的 android gradle 插件版本从类路径 'com.android.tools.build:gradle:2.3.0-beta4' 还原到类路径 'com.android.tools.build:gradle:2.2.3' 来解决此问题。
我正在使用 android studio 2.2.3。我所有的布局 xml 都在抱怨 "Missing styles"。以下是我在打开设计视图时遇到的错误。
呈现问题缺少样式。是否为此布局选择了正确的主题?使用布局上方的主题组合框选择不同的布局,或修复主题样式引用。 Failed to find style 'progressBarStyle' in current theme (1568 similar errors not shown) Failed to find '?attr/textAppearanceSmall' in current theme. (未显示 65 个类似错误)
我也注意到 styles.xml 找不到 "Theme.AppCompat.Light.NoActionBar"。我已经检查了项目结构,并且能够在依赖项列表中看到 com.android.support.appcompat-v7:25.2.0。我执行了无效缓存并重新启动,clean/build。但我无法摆脱缺少样式的问题。我还尝试将我的 "AppTheme" 重命名为 "AppBaseTheme" 并在我的 android 清单文件中引用它。即使那样也无济于事。我已经尝试在设计视图中进行刷新,但仍然无法摆脱缺少样式的错误。 对于另一个 xml 布局,我收到以下错误
Rendering Problems Missing styles. Is the correct theme chosen for this layout? >Use the Theme combo box above the layout to choose a different layout, or fix the theme style references. The following classes could not be instantiated: - android.support.design.widget.TabLayout (Open Class, Show Exception, Clear Cache) Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE. If this is an unexpected error you can also try to build the project, then manually refresh the layout. Exception Details java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library. at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:36) at android.support.design.widget.TabLayout.(TabLayout.java:297) at android.support.design.widget.TabLayout.(TabLayout.java:291) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) at android.view.LayoutInflater.rInflate(LayoutInflater.java:834) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) at android.view.LayoutInflater.inflate(LayoutInflater.java:518) at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
有人能给我指出正确的方向吗?谢谢。
以下是我的清单。
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:name=".ExampleApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".activity.SplashActivity"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".activity.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize"/>
</application>
以下是我的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "com.example.package"
minSdkVersion 18
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
jackOptions {
enabled true
}
dexOptions {
preDexLibraries true
javaMaxHeapSize "4g"
}
lintOptions {
abortOnError false
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
testOptions {
unitTests.returnDefaultValues = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
compile 'com.android.support:recyclerview-v7:25.2.0'
compile 'com.android.support:cardview-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.android.support:appcompat-v7:25.2.0'
compile group: 'joda-time', name: 'joda-time', version: '2.9.6'
compile group: 'com.google.guava', name: 'guava', version: '20.0'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'com.github.zagum:Android-SwitchIcon:1.3.2'
compile 'com.futuremind.recyclerfastscroll:fastscroll:0.2.5'
compile 'com.prolificinteractive:material-calendarview:1.4.2'
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
compile 'com.google.dagger:dagger:2.7'
annotationProcessor 'com.google.dagger:dagger-compiler:2.7'
testCompile 'junit:junit:4.12'
testCompile "org.robolectric:robolectric:3.0"
testCompile "org.robolectric:shadows-support-v4:3.0"
testCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
compile 'com.android.support.constraint:constraint-layout:1.0.0'
}
以下是我的styles.xml.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="android:textViewStyle">@style/RobotoTextViewStyle</item>
<item name="android:editTextStyle">@style/RobotoEditTextStyle</item>
</style>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/splash</item>
</style>
<style name="RobotoTextViewStyle" parent="android:Widget.TextView">
<item name="android:fontFamily">sans-serif</item>
<item name="android:textSize">@dimen/body</item>
<item name="android:textColor">@color/colorBlack</item>
</style>
<style name="RobotoEditTextStyle" parent="android:Widget.EditText">
<item name="android:fontFamily">sans-serif</item>
<item name="android:textSize">@dimen/body</item>
<item name="android:padding">@dimen/edittext_padding</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@android:color/white</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
<style name="TextInputLayoutStyle" parent="TextAppearance.AppCompat.Small">
<item name="android:textColor">@color/color_android_green</item>
<item name="android:textStyle">bold|italic</item>
</style>
<style name="TextInputLayoutStyleError" parent="TextAppearance.AppCompat.Small">
<item name="android:textColor">@color/colorRed</item>
<item name="android:textStyle">bold|italic</item>
</style>
<style name="CustomTextStyle" parent="@android:style/TextAppearance.Widget.TabWidget">
<item name="android:textSize">20sp</item>
</style>
<style name="CustomSwitch" parent="Theme.AppCompat.Light">
<!-- active thumb & track color (30% transparency) -->
<item name="colorControlActivated">@color/colorAccent</item>
<!-- inactive thumb color -->
<item name="colorSwitchThumbNormal">@color/colorGrayDarker</item>
<!-- inactive track color (30% transparency) -->
<item name="android:colorForeground">@color/colorGray</item>
</style>
<style name="CustomTabLayout" parent="Base.Widget.Design.TabLayout">
<item name="tabIndicatorColor">@color/colorGold</item>
<item name="tabSelectedTextColor">@color/colorGold</item>
</style>
<style name="StyledScrollerTextAppearance">
<item name="android:textColor">@color/colorWhite</item>
</style>
Tablayout xml 片段
<android.support.design.widget.TabLayout
android:id="@+id/callScheduleType"
style="@style/CustomTabLayout"
android:layout_width="0dp"
android:layout_height="40dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/guidelineNavHeight">
<android.support.design.widget.TabItem
android:id="@+id/personal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="personal"/>
<android.support.design.widget.TabItem
android:id="@+id/community"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="community"/>
</android.support.design.widget.TabLayout>
我能够通过将项目顶级构建文件中的 android gradle 插件版本从类路径 'com.android.tools.build:gradle:2.3.0-beta4' 还原到类路径 'com.android.tools.build:gradle:2.2.3' 来解决此问题。