java.lang.illegalstateexception:一个工厂已经设置这个layoutinflater工厂、lang、java、layoutinflater

2023-09-13 01:05:07 作者:念红颜夜无眠

我试图更改选项菜单的背景颜色在我的Andr​​oid应用程序。我使用ActionBarSherlock库。我曾尝试code更改选项菜单的背景颜色

I have tried to change the background color of options menu in my android app. I am using ActionBarSherlock library. I have tried this code for changing the background color of options menu

http://stackoverflow.com/a/8475357/584095

不过,我结束了一个异常java.lang.illegalstateexception:一个工厂已经设置这个layoutinflater的行

But I ended up with an exception "java.lang.illegalstateexception: a factory has already been set on this layoutinflater" at line

LayoutInflater.setFactory();

LayoutInflater.setFactory();

我不知道什么是错在这code。谁能帮我解决这个问题呢?

I don't know what is wrong in this code. Can anyone help me in resolving this issue?

推荐答案

有过一个变化在支持库,因为22.1.0版本。

There been a change in support library since version 22.1.0.

如果你试图调用 getLayoutInflater(),你会得到一个IllegalStateException。setFactory()

您应该使用新的API

You should use the new api

LayoutInflaterCompat.setFactory() AppCompatActivity而不是pcated德$ P $ ActionBarActivity LayoutInflaterCompat.setFactory() AppCompatActivity instead of deprecated ActionBarActivity

或者干脆用老版本

com.android.support:appcompat-v7:22.0.0 com.android.support:appcompat-v4:22.0.0 com.android.support:appcompat-v7:22.0.0 com.android.support:appcompat-v4:22.0.0