简体   繁体   English

在Android <5.0上未显示ActionBar

[英]ActionBar not showing on android < 5.0

I switched from ABS to AppCompat and Material theme(for api 21 only) 我从ABS切换到AppCompat和Material主题(仅适用于api 21)

<!--manifest: -->
<application
        android:theme="@style/AppStyle"

<-- values folder -->
<style name="AppStyle" parent="@style/AudioRecTheme">
<style name="AudioRecTheme" parent="@style/Theme.AppCompat.Light">

<!-- values-v21 folder-->
<style name="AudioRecTheme" parent="@android:style/Theme.Material.Light">

My activity: 我的活动:

public class AudioRecActivity extends FragmentActivity

The action bar is showing only in Android 5.0, but missing otherwise. 动作栏仅在Android 5.0中显示,否则丢失。

First, either use appcompat-v7 or use built-in themes, not both for the same activity. 首先,使用appcompat-v7 使用内置主题,而不是同时针对同一活动。 Here, you are trying to use Theme.AppCompat.Light in some cases and Theme.Material.Light in others, which is not only unnecessary but AFAIK will not work. 在这里,你要使用Theme.AppCompat.Light在某些情况下和Theme.Material.Light在其他国家,这不仅是不必要的,但据我所知将无法正常工作。 If you are going to use Theme.AppCompat.Light , do so for all API levels. 如果要使用Theme.AppCompat.Light ,请对所有API级别使用。

Second, if you are going to use appcompat-v7 and Theme.AppCompat.Light , you need to inherit from ActionBarActivity . 其次,如果要使用appcompat-v7Theme.AppCompat.Light ,则需要从ActionBarActivity继承。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM