本文介绍了维护与材料设计向后兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想实现具有材质设计有色标题栏的活动。
I'm trying to implement an activity that has the Material Design tinted title bar.
我的标准样式是:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> </style>我的V21的风格是:
My v21 style is:
<style name="AppTheme" parent=" -see rest of this post- "> <item name="android:colorPrimary">@color/primary</item> <item name="android:colorPrimaryDark">@color/primary_dark</item> <item name="android:colorAccent">@color/accent</item> </style>和我得到的结果是:
API 18: MyActivity extends AppCompatActivity -- Black title bar, this is good enough. MyActivity extends Activity: -- No title bar. API 21: MyActivity extends Activity, parent="android:Theme.Material.Light" -- Perfect green tinting of status bar and title bar. MyActivity extends AppCompatActivity, parent="android:Theme.Material.Light" -- Crashes with: You need to use a Theme.AppCompat theme (or descendant) with this activity. MyActivity extends AppCompatActivity, parent="Theme.AppCompat.Light" -- Status bar is correctly green tinted. Title bar has no background colour. MyActivity extends AppCompatActivity, parent="Theme.AppCompat.Light.DarkActionBar" -- Status bar is correctly green tinted. Title bar has black background colour.我如何获得棒棒糖和彩色标题栏为可接受的pre-棒棒糖?我知道有一些额外的工作,我可以有一个彩色的pre-棒棒糖标题栏,但不是在这个时候需要的。
How do I get the coloured title bar in Lollipop and an acceptable one pre-Lollipop? I know with extra work I can have a coloured pre-lollipop title bar, but that is not needed at this time.
推荐答案您应该使用带有支持库的非Android名称空间的属性:
You should be using the non-android namespaced properties with the support library:
<style name="AppTheme" parent="Theme.AppCompat.Light"> <item name="colorPrimary">@color/primary</item> <item name="colorPrimaryDark">@color/primary_dark</item> <item name="colorAccent">@color/accent</item> </style>无需V21版本。这会给你一致的行为,回到API级别7
No v21 version required. This will give you consistent behavior back to API level 7
更多推荐
维护与材料设计向后兼容
发布评论