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

前端 未结 14 932
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

    getSupportActionBar().getThemedContext()
    
    AlertDialog.Builder builder;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder = new AlertDialog.Builder(getSupportActionBar().getThemedContext(), android.R.style.Theme_Material_Dialog_Alert);
    } else {
        builder = new AlertDialog.Builder(getSupportActionBar().getThemedContext());
    }
    builder.setTitle("Alert Dialog")
           .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
    
                }
            })
           .setIcon(android.R.drawable.ic_dialog_alert)
           .show();
    

提交回复
热议问题