java.lang.illegalstateexception: a factory has already been set on this layoutinflater

后端 未结 5 606
轻奢々
轻奢々 2020-12-06 11:57

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

5条回答
  •  失恋的感觉
    2020-12-06 12:14

    I faced the same issue but no answer helped me.

    In my case:

    • I'm extending AppCompatActivity

    • Project targeting API 27

    • Implementation support lib 27.1.1

    Solution: Apparently, now there is no need of setting the Factory to the LayoutInflater, it would crash or be ignored. Just override both methods onCreateView(...) in your AppCompatActivity (from android.support.v4.app.BaseFragmentActivityApi14)

    public class myActivity extends AppCompatActivity  {
        ...
        @Override
        public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
            if (name.compareTo("EditText") == 0) {
                CustomEdit newEdit = new CustomEdit(this,attrs); 
                return newEdit;
            }
            return super.onCreateView(parent, name, context, attrs);
        }
        @Override
        public View onCreateView(String name, Context context, AttributeSet attrs) {
            return onCreateView(null, name, context, attrs);
        }
        ...
    }
    

提交回复
热议问题