"@android:style/Theme.Material.Light`的Android错误

nil*_*ash 6 android styles material-design

您好我正在构建一个具有一些材料设计概念的Android示例应用程序.我从https://developer.android.com/training/material/theme.html开始.我正在使用eclipse.我在我的项目的库部分添加了appcompat_7支持库.然后当我尝试应用以下主题时.

 <style name="AppTheme" parent="@android:style/Theme.Material.Light">

</style>
Run Code Online (Sandbox Code Playgroud)

它给我以下运行时错误:

11-12 11:32:30.416: E/AndroidRuntime(21375): java.lang.RuntimeException: Unable to start activity
 ComponentInfo{com.example.androidmaterialdesignapi/com.example.androidmaterialdesignapi.MainActivity}: 
 java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
Run Code Online (Sandbox Code Playgroud)

我的活动延伸了ActionBarActivity.我做错了什么.需要一些帮助.谢谢.学习材料设计有什么好的例子吗?

vir*_*rao 4

是的,当您使用 ActionBar 活动作为父活动时,您需要将 Theme.AppCompat 作为自定义主题的父样式。

按如下方式替换您的线路:

<style name="AppTheme" parent="@style/Theme.AppCompat">
Run Code Online (Sandbox Code Playgroud)

而不是这个

<style name="AppTheme" parent="@android:style/Theme.Material.Light">
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你。