2015-11-13 54 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)