LoginSignup
5

More than 5 years have passed since last update.

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

Last updated at Posted at 2015-04-24

この記事の事象は、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);
    }
}

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5