安卓自定义弹窗

 

安卓自定义弹窗_第1张图片

showDialogGPSOpen(mainActivity.this); 

//弹框判断GPS是否开启
    private void showDialogGPSOpen(final Context context) {
        View view = getLayoutInflater().inflate(R.layout.dialog_2, null);
       //取消
        final TextView cancel = (TextView) view.findViewById(R.id.cancel);
       //确定
        final TextView save = (TextView) view.findViewById(R.id.save);
        final AlertDialog dialog = new AlertDialog.Builder(context)
                .setView(view)
                .create();
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               // Toast.makeText(context, "系统检测到未开启GPS定位服务", Toast.LENGTH_LONG).show();
                Intent intent=new Intent();
                intent.setAction(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                startActivity(intent);
            }
        });

    }

 

你可能感兴趣的:(Android开发)