我有几部手机,一部运行Android 6.0 Marshmallow的infinix热门笔记本和运行最新最好的Android 8.0 Oreo的Nexus 6P。
我正在测试一个应用程序,该应用程序只允许用户在特定位置附近输入数据时我注意到在Oreo上我的AlertDialogs中的所有消息都没有显示。它们显示为空白(或者可能以白色文字或其他颜色着色)。
我在非洲,我正在支持运行android 9的设备
(旧手机永远不会被丢弃,直到它们到期为止)
所以gradle设置是
minSdkVersion 9
targetSdkVersion 22
compileSdkVersion 25
buildToolsVersion '25 .0.0'
我附上了Nexus和Infinix对话框的截图。 任何人都知道如何绕过这种行为?以下是两个设备中使用的完整代码
提前感谢任何花时间查看此问题的人。
private void showNotNearOutlet(ProximityToOutlet proximityToOutlet, String OutletName) {
String strMsg = "";
int intAllowedProximity = GSR.getSavedSettings.getAllowedProximityToOutletMeters();
float floatDistanceFromOutlet = proximityToOutlet.getFltDistanceBetweenCurrentLocAndOutlet();
String strDistance = String.valueOf(df.format(floatDistanceFromOutlet)) + "m";
if (floatDistanceFromOutlet > 1000) {
strDistance = df.format(floatDistanceFromOutlet / 1000) + "Km";
}
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setTitle("Cannot start outlet!");
if (floatDistanceFromOutlet != -99) { /*means we cant get a good location fix at the moment*/
strMsg = "GPS shows your current location as being " + strDistance + " from " + OutletName + " .\n\nYou must be at least " + intAllowedProximity + " Meters near the Outlet to start it.";
} else {
strMsg = "Cannot Start outlet because your current GPS position is undetermined.\nTap on 'Locate Me' button and wait till you get a GPS Fix or Accuracy is within 20meters.\n\nTo start an Outlet you must be within " + intAllowedProximity + " meters of it.";
}
alertDialogBuilder.setCancelable(true);
alertDialogBuilder.setIcon(R.drawable.red_gps_icon);
alertDialogBuilder.setMessage(strMsg);
alertDialogBuilder.setPositiveButton("Close", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//fetchOutletsForSpinner();
setSpinnerToSelectOutlet();
dialog.dismiss();
}
});
alertGPS = alertDialogBuilder.create();
if (!MainActivity.this.isFinishing()) {
//show dialog
alertGPS.show();
blnGPSAlertIsVisible = true;
}
}
[在Android Oreo中缺少AlertDialog文本(左)。有趣的是,在8.0之前的版本中缺少gps图标[1] 1(右)
答案 0 :(得分:3)
ContentPage
在API级别22中已弃用,请使用android.util.FloatMath
代替API> 21。
同时将compileSdkVersion 25改为26,buildToolsVersion '25 .0.0'改为'26 .0.2'