android关于使用Design库遇到的异常

来源:互联网 发布:淘宝代付能看到地址吗 编辑:程序博客网 时间:2024/06/05 02:11

在使用android5.0新特性的一些控件时,需要先compile一些库:

 compile 'com.android.support:appcompat-v7:23.1.1'    compile 'com.android.support:design:23.1.1'

然而我在使用的时候仍然报错,系统提示异常信息未, you need a theme appcomt 作为该activity 的样式。于是乎,我打开style文件:

 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">        <!-- Customize your theme here. -->        <item name="windowNoTitle">true</item>        <item name="colorPrimary">@color/colorPrimary</item>        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>        <item name="colorAccent">@color/colorAccent</item>        <item name="android:colorPressedHighlight">@color/colorAccent</item>        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>        <item name="android:actionMenuTextColor">@android:color/white</item>    </style>
然而就是compat样式。

到底出了什么问题?
原来,我做了一个工具类,用的LayoutInflater得到了一个View,然而由此得到的view并没有引用到我们的Apptheme主题,所以该怎么办呢?
如下:
ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(getContext(), R.style.AppTheme);        LayoutInflater layoutInflater = LayoutInflater.from(getContext()).cloneInContext(contextThemeWrapper);

由此得到的layoutInflater就是填充了apptheme主题的了,接下来就去使用他吧!

0 0
原创粉丝点击