AppCompat22.1.0でFragmentにAppComatXXViewが適用されない


この記事の事象は、AppCompat 22.1.1で修正済みです。

バグの事象

22.1.0のAppCompatActivity(旧ActionBarActivity)を適用すると、FragmentのinflateにActivityのLayoutInflaterが適用されない

既に、Future Relaseになってますが、現時点の対応方法として2つあります。

修正方法その1

22.1.0以前の実装を自分で書いてやればいいだけです。
BaseActivityを作っている人は1行で終わります。

BaseActivity
public class BaseActivity extends AppCompatActivity {

    @Override
    public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
        // DelegateのcreateView()をreturnするようにする
        return getDelegate().createView(parent, name, context, attrs);
    }

}

修正方法その2

Issueコメントにあるように、引数のLayoutInflaterではなく、getActivity().getLayoutInflater()を利用します。

HogeFragment

public class HogeFragment extends Fragment {

    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        // getActivity().getLayoutInflater()を使う
        return getActivity().getLayoutInflater().inflate(R.layout.fragment_security, null, false);
    }
}