AppCompatActivity vs AppCompatDelegate

做~自己de王妃 提交于 2019-12-10 23:15:27

问题


Recently I discovered what is AppCompatDelegate so a natural question arises - is it worse than using AppCompatActivity or do they have their differences and what are they?


回答1:


If your activity class is not extending AppCompatActivity but you still want to use some of its features then you can you AppCompatDelegate.

You can create Appcompatdelegate with following lines of code in your activity class:

private AppCompatDelegate getDelegate() {
    if (mDelegate == null) {
       mDelegate = AppCompatDelegate.create(this, null);
    }
    return mDelegate;
}

Here is the example if you want to add Toolbar in your activity but your class is not extending AppCompatActivity.

https://medium.com/google-developer-experts/how-to-add-toolbar-to-an-activity-which-doesn-t-extend-appcompatactivity-a07c026717b3



来源:https://stackoverflow.com/questions/44895978/appcompatactivity-vs-appcompatdelegate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!