Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使对话框在2.2到4.4的所有版本以及所有平板电脑中看起来相同_Android_Dialog_Android Alertdialog - Fatal编程技术网

Android 如何使对话框在2.2到4.4的所有版本以及所有平板电脑中看起来相同

Android 如何使对话框在2.2到4.4的所有版本以及所有平板电脑中看起来相同,android,dialog,android-alertdialog,Android,Dialog,Android Alertdialog,如何使dialog在2.2到4.4的所有版本以及所有平板电脑中看起来都一样。我已经创建了dialog,它在4.2中看起来很完美,我希望在2.3中也能看到同样的dialog。如何使dialog在2.2到4.4的所有版本以及所有平板电脑中看起来都一样。我已经创建了dialog,它在4.2中看起来很完美,我希望在2.3中也能看到同样的dialog还有 public class MainActivity extends Activity { private Context context; privat

如何使dialog在2.2到4.4的所有版本以及所有平板电脑中看起来都一样。我已经创建了dialog,它在4.2中看起来很完美,我希望在2.3中也能看到同样的dialog。如何使dialog在2.2到4.4的所有版本以及所有平板电脑中看起来都一样。我已经创建了dialog,它在4.2中看起来很完美,我希望在2.3中也能看到同样的dialog还有

public class MainActivity extends Activity {
private Context context;
private TextView textView;
private Dialog dialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    context = MainActivity.this;
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(
            MainActivity.this);
    LayoutInflater inflater = MainActivity.this.getLayoutInflater();
    alertDialog.setView(inflater.inflate(R.layout.dialog_textview, null));



    // Setting Positive "Yes" Button
    alertDialog.setPositiveButton("Call",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                    // Write your code here to invoke YES event
                    if (deviceIsTablet(context)) { // if device is a
                        // tablet
                        if (isAppInstalled("com.skype.raider")) {
                            // insert what you want to do if device has
                            // skype
                            Intent intent = new Intent(
                                    "android.intent.action.VIEW");
                            intent.setData(Uri.parse("skype:" + 123456789));
                            startActivity(intent);
                        } else {
                            // connect to Play store or whatever
                            startActivity(new Intent(
                                    Intent.ACTION_VIEW,
                                    Uri.parse("http://play.google.com/store/apps/details?id=com.skype.raider")));
                        }
                    } else { // if device is not a tablet
                        Intent callIntent = new Intent(Intent.ACTION_CALL);
                        callIntent.setData(Uri.parse("tel:123456789"));
                        startActivity(callIntent);
                    }
                }
            });

    // Setting Negative "NO" Button
    alertDialog.setNegativeButton("Cancel",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    // Write your code here to invoke NO event

                }
            });

    // Showing Alert Message
    alertDialog.show();

}

// determine whether or no the android device is a tablet or not
public static boolean deviceIsTablet(Context c) {
    Resources res = c.getResources();
    return (res.getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

private boolean isAppInstalled(String appToCheck) {
    PackageManager pm = getPackageManager();
    boolean isOnDevice = false;
    try {
        pm.getPackageInfo(appToCheck, PackageManager.GET_ACTIVITIES);
        isOnDevice = true;
    } catch (PackageManager.NameNotFoundException exception) {
        isOnDevice = false;
    }
    return isOnDevice;
}

}

检查以下链接以创建自定义对话框:

创建自定义对话框的步骤:

创建布局文件,例如dialog.xml 在活动中引用dialog.xml类。 将新布局文件与对话框视图捆绑在一起。 显示对话框。
您需要创建自定义对话框。不建议使用仅链接的答案。将链接发布为常用或详细说明您的answer@Raghunandan更新了我的答案。