You need to use a Theme.AppCompat theme (or descendant) with this activity. Change to Theme.AppCompat causes other error

前端 未结 14 927
Happy的楠姐
Happy的楠姐 2020-11-27 15:47

I use appcompat v22.1.0 in my App and use Toolbar. Everything was fine when I use Theme.AppCompat.Light.NoActionBar. When I start implement AlertDialog

14条回答
  •  情深已故
    2020-11-27 16:28

    If you are using support library your activity extends AppCompactActivity, if you use android studio to create activity this is default. In such case pass context to the builder as ActivityName.this or simply this if you are passing it in onCreate, passing getApplicationContext() will not work.

    This is my style using appcompact

    
    
        
    

    And everything is working fine when I use this or ActivityName.this as mentioned above (here ActivityName is the name of your current activity i.e. MainActivity.this).

    If you are using in fragment you should pass getActivity() as context to builder instead of getContext().

提交回复
热议问题