2015-11-13 78 views
0

我正在使用适用于Android的Google设计支持库。我想有一个RelativeLayout,它里面有一个FloatingActionButton。问题是,我用充气的观点:以编程方式膨胀AppCompat主题

mLayoutInflater.inflate(window.getLayoutResource(), null) 

我得到抛出的异常,告诉我说,家长必须使用程序兼容性主题为设计库。

Caused by: java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library. 

我能做些什么来扩大没有活动的主题附属于他们的布局?

回答

0

解决方案是指定使用AppCompat的XML内的最高布局的主题。

即:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:theme="@style/AppTheme" 
    .... 

然后,所有其下的元件将膨胀,通常使用

mLayoutInflater.inflate(window.getLayoutResource(), null)