Android的材料设计与AppCompatActivity [英] android material design with AppCompatActivity

查看:204
本文介绍了Android的材料设计与AppCompatActivity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要支持API 19岁及以下,我让我的活动扩展AppCompatActivity。
我试图为V21以下父主题父=机器人:Theme.Material
当我试图跑到我的应用程序它给了一个异常,并告诉我使用的活动,而不是AppCompatActivity。

To support API 19 and below I let my activities extend AppCompatActivity. I tried to set the following parent theme for v21 parent="android:Theme.Material" When I tried to ran my app it gave an exception and told me to use Activity instead of AppCompatActivity.

这是否意味着我必须创建一个为了得到材料设计API 21及以上的延伸活动新活动?还是有更好的办法?

Does this mean I have to create new Activities which extend Activity for API 21 and above in order to get material design? Or is there a better way?

推荐答案

AppCompatActivity 需要的应用程序兼容性主题即可。
使用不同的主题,如的android:Theme.Material 您将获得

The AppCompatActivity requires an AppCompat theme. Using a different theme, like the android:Theme.Material you will get

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity

就在您的styles.xml文件中定义一个主题:

Just define a Theme in your styles.xml file:

<style name="AppTheme" parent="Theme.AppCompat">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>

    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

随着应用程序兼容性主题,你可以有材质的设计也符合API&LT设备; 21

With the AppCompat theme you can have the Material design also in device with API <21.

的android:Theme.Material 只能用API使用> = 21

The android:Theme.Material can be use only with API >= 21.

这篇关于Android的材料设计与AppCompatActivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆