维护与材料设计向后兼容

编程入门 行业动态 更新时间:2024-10-13 06:19:40
本文介绍了维护与材料设计向后兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想实现具有材质设计有色标题栏的活动。

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

更多推荐

维护与材料设计向后兼容

本文发布于:2023-11-13 22:52:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585540.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:材料

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!