我正在使用Android Studio,我的
values/styles.xml
中出现了与资源相关的问题。它说无法解析
@style/Theme.AppCompat.Light
,但在编译时(gradle)和运行时(Android 2.3.3和4.3)一切都正常。我想要消除这个资源无法解析的警告。
以下是我的操作步骤。希望这可以帮到你,欢迎提出建议。
appcompat库的源代码可以在github上找到。
Gradle集成:
dependencies {
...
compile group:'com.android.support', name:'appcompat-v7', version:'18.0.+'
...
}
样式文件:
values/styles.xml:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
<item name="actionBarStyle">@style/ActionBar.Solid.Custom</item>
</style>
<style name="ActionBar.Solid.Custom" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="background">@drawable/ab_solid_custom</item>
<item name="displayOptions">homeAsUp|showHome|showCustom</item>
</style>
</resources>
values-v14/styles.xml:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
</style>
<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/ActionBar.Solid.Custom</item>
</style>
<style name="ActionBar.Solid.Custom" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:background">@drawable/ab_solid_custom</item>
<item name="android:displayOptions">homeAsUp|showHome|showCustom</item>
</style>
</resources>
MainActivity (只有扩展是强制性的):
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Views.inject(this);
setupNavigationDrawer();
}
}
AndroidManifest.xml (设置android:theme是必须的):
<activity
android:name="com.example.app.MainActivity"
android:theme="@style/AppTheme"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>